1//The unshift() method adds one or more elements to the beginning of an array
2//and returns the new length of the array.
3
4const array1 = [1, 2, 3];
5console.log(array1.unshift(4, 5));
6// expected output: 5
7console.log(array1);
8// expected output: Array [4, 5, 1, 2, 3]
1var name = [ "john" ];
2name.unshift( "charlie" );
3name.unshift( "joseph", "Jane" );
4console.log(name);
5
6//Output will be
7[" joseph "," Jane ", " charlie ", " john "]
1let cats = ['Bob', 'Willy', 'Mini'];
2
3cats.shift(); // ['Willy', 'Mini']
4
5let cats = ['Bob'];
6
7cats.unshift('Willy'); // ['Willy', 'Bob']
8
9cats.unshift('Puff', 'George'); // ['Puff', 'George', 'Willy', 'Bob']