length property
The length property allows
you to find out and set the length
of an array.
Syntax
array.length;
Example
Let's output the length of
the array arr:
let arr = ['a', 'b', 'c', 'd', 'e'];
console.log(arr.length);
The code execution result:
5
Example
Let's reduce the array to
2 elements:
let arr = ['a', 'b', 'c', 'd', 'e'];
arr.length = 2;
console.log(arr);
The code execution result:
['a', 'b']