How to use Array push() JavaScript Language

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

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

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

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