Answers for "unshift() adds elements to the beginning of an array"

10

unshift method in javascript

var name = [ "john" ];
name.unshift( "charlie" );
name.unshift( "joseph", "Jane" );
console.log(name);

//Output will be
[" joseph "," Jane ", " charlie ", " john "]
Posted by: Guest on August-02-2020
0

how to use unshift() and shift()

//to add the first item to a array 

let top_salespeople = ['Lucy', 'Graham', 'Carol', 'Ann'];
top_salespeople.unshift('Hannah');

console.log(top_salespeople);
Posted by: Guest on August-24-2021

Code answers related to "unshift() adds elements to the beginning of an array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language