How to use Array push() JavaScript Language

Array push

Array Push() Method

Program to use Array Push() Method JavaScript Language

let a = [1, 2, 3];
    a.push(4, 5);
    console.log(a);
    

Output

[ 1, 2, 3, 4, 5 ]
    

Steps Description

  • Declare variable a
  • Initialise variable a with value of array a = [1, 2, 3]
  • The push() method of an array adds one or more elements to the end of the array.
  • The value of a variable is displayed with the help of console.log inbuilt function

Array Push() Method

Program to use Array Push() Method JavaScript Language

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

Output

[ 'Cat', 'Dog', 'Tiger', 'Lion', 'Elephant' ]
    

Steps Description

  • Declare variable b
  • Initialise variable b with value of array b = [‘Cat’,’Dog’,’Tiger’]
  • The push() method of an array adds one or more elements to the end of the array.
  • The value of b variable is displayed with the help of console.log inbuilt function