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
⭐ Must Read: forwardschool/how to get array length in solidity a - Kapook Update 2025 ⭐ Must Read: forwardschool/how to get array length in solidity a - Kapook Update 2025

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]
⭐ Must Read: forwardschool/how to get array length in solidity a - Kapook Update 2025 ⭐ Must Read: forwardschool/how to get array length in solidity a - Kapook Update 2025

To get the length of values, you can write:

uint len = values.length
⭐ Must Read: forwardschool/how to get array length in solidity a - Kapook Update 2025 ⭐ Must Read: forwardschool/how to get array length in solidity a - Kapook Update 2025

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

Hope that helps.

Top comments (0)