DEV Community

Jeremy Ikwuje for Monierate Engineering Blog

Posted on

How to get array length in Solidity

Solidity has a special array property called .length that returns the Length of an Array.

array.length
Enter fullscreen mode Exit fullscreen mode

The length of an Array is the total number of indexes, positions, or values in that array.

Let's say you have an array called values containing integers as below:

int[] values = [15, 10, 14, 45]
Enter fullscreen mode Exit fullscreen mode

To get the length of values, you can write:

uint len = values.length
Enter fullscreen mode Exit fullscreen mode

The variable len is now the length of values in this case 4 (an unsigned integer).

Hope that helps.

Top comments (0)