shift vs unshift js code example
Example 1: javascript remove first item from array
var colors = ["red", "green", "blue"];
var red=colors.shift();
Example 2: unshift method in javascript
var name = [ "john" ];
name.unshift( "charlie" );
name.unshift( "joseph", "Jane" );
console.log(name);
[" joseph "," Jane ", " charlie ", " john "]
Example 3: shift and unshift js
let cats = ['Bob', 'Willy', 'Mini'];
cats.shift();
let cats = ['Bob'];
cats.unshift('Willy');
cats.unshift('Puff', 'George');
Example 4: unshift javascript
let twentyThree = 'XXIII';
let romanNumerals = ['XXI', 'XXII'];
romanNumerals.unshift('XIX', 'XX');
romanNumerals.push(twentyThree);
Example 5: js unshift vs push
var array = [2];
array.push(3)
array.unshift(1)