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