Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

push and unshift in javascript

/*
The push() method adds new items to the end of an array.
The unshift() method adds new elements to the beginning of an array.
*/

const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.unshift("Lemon", "Pineapple"); //Lemon,Pineapple,Banana,Orange,Apple,Mango

const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi"); //Banana,Orange,Apple,Mango,Kiwi
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #push #unshift #javascript
ADD COMMENT
Topic
Name
4+2 =