Using Array.shift() and Array.unshift() in Javascript


.shift() removes the first element, and .unshift() adds elements to the beginning of an array.

Source Code

let fruits = ['apple', 'banana'];
fruits.unshift('orange'); // ['orange', 'apple', 'banana']
let firstFruit = fruits.shift(); // ['apple', 'banana']
console.log(firstFruit); // "orange"
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments