offline version v3


90 of 264 menu

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

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
enru