June 3, 2023
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 arraya = [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 ofconsole.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
- Declare variable
b
- Initialise variable
b
with value of arrayb = ['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 ofconsole.log
inbuilt function
by : Suhel Akhtar
Quick Summary:
JavaScript Array push() Method two example number and string