JavaScript

June 6, 2023

How to use JavaScript Array length

Program to use JavaScript Array length


let a = ['Cat', 'Dog', 'Tiger', 'Lion', 'Elephant'];
let b = a.length;
console.log(b);

Output


5

Steps Description

  1. Declare two variable a and b
  2. Initialize two variable with value of array a = ['Cat', 'Dog', 'Tiger', 'Lion', 'Elephant'] and b
  3. The array length() method outputs the index numbers of the array elements.
  4. The value of b variable is displayed with the help of console.log inbuilt function

Program to use JavaScript Array length


let c = ['Cat', 'Dog', 'Tiger', 'Lion', 'Elephant'];
c.length = 3
console.log(c);

Output


[ 'Cat', 'Dog', 'Tiger' ]

Steps Description

  1. Declare variable c
  2. Initialize variable with value of array c = ['Cat', 'Dog', 'Tiger', 'Lion', 'Elephant']
  3. The array length() method outputs the index numbers of the array elements.
  4. The value of c variable is displayed with the help of console.log inbuilt function

Program to use JavaScript Array length


let d = [1,2,3,4,5,6,7,8,9,10];
let e = d.length;
console.log(e);

Output


10

Steps Description

  1. Declare two variable d and e
  2. Initialize two variable with value of array d = [1,2,3,4,5,6,7,8,9,10] and e = d.length
  3. The array length() method outputs the index numbers of the array elements.
  4. The value of e variable is displayed with the help of console.log inbuilt function

Tags:

by : Suhel Akhtar

Quick Summary:

JavaScript Array length