javascript unshit code example

Example 1: javascript unshift

let array = ["A", "B"];
 let variable = "what you want to add";

//Add the variable to the beginning of the array
 array.unshift(variable);

//===========================
 console.log(array);
//output =>
//["what you want to add" ,"A", "B"]

Example 2: unshift javascript

/*The unshift() adds method elements to the beginning, and push() method 
adds elements to the end of an array.*/
let twentyThree = 'XXIII';
let romanNumerals = ['XXI', 'XXII'];

romanNumerals.unshift('XIX', 'XX');
// now equals ['XIX', 'XX', 'XXI', 'XXII']

romanNumerals.push(twentyThree);
// now equals ['XIX', 'XX', 'XXI', 'XXII', 'XXIII']