THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.
The array is a fixed or dynamic compile time in solidity.
Sometimes, We want to find the array length to check several elements in Solidity.
Solidity Array provides a length property to return the number of array elements in it.
First, Array is created by initializing static data.
Next, create a size() public function which returns the count of elements in an array.
length
property returns the number of elements in an array
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.7;
contract test {
string[3] numbers=["one","two","three"];
function size() public view returns(uint){
return numbers.length;;
}
}
Output:
{
"0": "uint256: 3"
}
🧮 Tags
Recent posts
Julia examples - Variable Type Nim example - Convert String to/from the Int How to get length of an array and sequence in Nim? Nim environment variables - read, set, delete, exists, and iterate examples? How to convert from single character to/from string in Nim?Related posts