DEV Community

Jeremy Ikwuje for Monierate Engineering Blog

Posted on

1

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)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay