Length

Arrays have a property called length, and it's pretty much exactly as it sounds, it's the length of the array.

let array = [1, 2, 3];

let l = array.length;

// Result: l = 3

The length property also sets the number of elements in an array. For example.

const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.length = 2;

console.log(fruits);
// ['Banana', 'Orange']

Last updated

Was this helpful?