user
How to get array length in JavaScript?
alphonsio

To get the length of an array in JavaScript, use the .length property.


Example:

const fruits = ["apple", "banana", "cherry"];
console.log(fruits.length); // Output: 3

Key Points:

  • .length gives the number of elements in the array.
  • It updates automatically when the array changes.

Example with push:

fruits.push("orange");
console.log(fruits.length); // Output: 4