OneBite.Dev - Coding blog in a bite size

find the length of an array in Javascript

Code snippet on how to find the length of an array in Javascript

 var myArray = [10,20,30,40,50];
 
 var arrayLength = myArray.length;
 console.log(arrayLength);

The code above will find the length of an array. First, the variable myArray contains the array that is being measured. This array consists of 5 elements. Next, a variable, arrayLength, is declared and assigned to the length of myArray. The length of the array can be determined by using the JavaScript length property. Lastly, the length of the array is printed out to the console by using the console.log() method. This code will output the number 5, which is the length of the array.

javascript