How to use JavaScript Array length

Array length

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

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

Array length

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

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

Array length

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

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