arr.unshift in javascript code example
Example 1: unshift method in javascript
var name = [ "john" ];
name.unshift( "charlie" );
name.unshift( "joseph", "Jane" );
console.log(name);
[" joseph "," Jane ", " charlie ", " john "]
Example 2: insert element at beginning of array javascript
const array = [3, 2, 1]
const newFirstElement = 4
const newArray = [newFirstElement].concat(array)
console.log(newArray);
Example 3: shift and unshift js
let cats = ['Bob', 'Willy', 'Mini'];
cats.shift();
let cats = ['Bob'];
cats.unshift('Willy');
cats.unshift('Puff', 'George');