how to check the length of array in solidity

The solution for “how to check the length of array in solidity” can be found here. The following code will assist you in solving the problem.

uint8[3] fixedList;
// fixedList.length => 3

uint8[] dynamicList;
uint8.push(1)
uint8.push(2)
// dynamicList.length => 2// Solidity program to demonstrate
// Push operation
pragma solidity ^0.5.0;  

// Creating a contract
contract Types {  

    // Defining the array
    uint[] data = [10, 20, 30, 40, 50]; 

    // Defining the function to push
    // values to the array
    function array_push(
    ) public returns(uint[] memory,uint256 length){  

        data.push(60);
        data.push(70);
        data.push(80);

        return (data,length);
    }
}// Solidity program to demonstrate
// Push operation
pragma solidity ^0.5.0;  

// Creating a contract
contract Types {  

    // Defining the array
    uint[] data = [10, 20, 30, 40, 50]; 

    // Defining the function to push
    // values to the array
    function array_push(
    ) public returns(uint[] memory){  

        data.push(60);
        data.push(70);
        data.push(80);

        return data;
    }
}

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

Similar Posts