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']

See also

  • the length property
    that allows you to find the length of the string
  • the find method
    that looks for an element in an array