To get the length of an array in JavaScript, you can use the length
property of the array.
In this example,
numbers
with some values.length
property of the array object numbers
, and store the returned value in length
variable.Array.length
property returns the length of this array.length
to standard output.let numbers = [1, 2, 3, 4, 5];
let length = numbers.length;
console.log(`Length of array is: ${length}`);
Length of array is: 5
In this example,
colors
with some values.length
property of the array object colors
, and store the returned value in length
variable.Array.length
property returns the length of this array.length
to standard output.let colors = ['red', 'green', 'blue'];
let length = colors.length;
console.log(`Length of array is: ${length}`);
Length of array is: 3
In this tutorial, we learned How to Get Array Length in JavaScript language with well detailed examples.