Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

difference between shift and unshift in javascript

// Shift (remove) the first element of the array:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.shift(); //Orange,Apple,Mango

// Add new elements to an array:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.unshift("Lemon","Pineapple"); //Lemon,Pineapple,Banana,Orange,Apple,Mango

 
PREVIOUS NEXT
Tagged: #difference #shift #unshift #javascript
ADD COMMENT
Topic
Name
4+5 =