How to get array length in a solidity| Solidity by example

“The array in Solidity can be either fixed or dynamically compiled at runtime.

At times, we may need to determine the array length to check various elements in Solidity.

Solidity arrays offer a length property, which returns the number of elements in the array.

How to find the length of an array in solidity

Initially, an array is created by initializing static data. Subsequently, a public function called size() is created, which returns the count of elements in the array. The length property is used to obtain the number of elements in the 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;;



    "0": "uint256: 3"