Search
 
SCRIPT & CODE EXAMPLE
 

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

Comment

shift and unshift js

let cats = ['Bob', 'Willy', 'Mini'];

cats.shift(); // ['Willy', 'Mini']

let cats = ['Bob']; 

cats.unshift('Willy'); // ['Willy', 'Bob']

cats.unshift('Puff', 'George'); // ['Puff', 'George', 'Willy', 'Bob'] 
Comment

PREVIOUS NEXT
Code Example
Javascript :: string contains javascirpt 
Javascript :: iffi in js 
Javascript :: Update nextjs to 11 
Javascript :: search content in js 
Javascript :: date options js 
Javascript :: remove duplicates from array of objects javascript 
Javascript :: useHistory react testing 
Javascript :: how get one value of array of object in javascript 
Javascript :: nodejs recursively read directory 
Javascript :: how to convert a JavaScript iterator to array 
Javascript :: adding event listener keypress event in javascript 
Javascript :: js change button text 
Javascript :: js minifier api 
Javascript :: javascript get date name 
Javascript :: setinterval break 
Javascript :: add border to view react native 
Javascript :: jquery word count 
Javascript :: jq object to dom object convert 
Javascript :: regular expression match text between quotes 
Javascript :: JAVASCRIPT ARRRAY LOOP BACKWARDS 
Javascript :: Javascript push a key value pair into a nested object array 
Javascript :: convert a string to an integer in javascript 
Javascript :: compare NaN in javascript if condititon 
Javascript :: how to calculate distance between two points in javascript 
Javascript :: javascript radio button onchange 
Javascript :: regex on input 
Javascript :: how to right plain text format file in node js 
Javascript :: change href with jquery 
Javascript :: flatlist react native 
Javascript :: angular access form control value 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =