Answers for "how to add an item to the beginning of an array js"

73

javascript push item to beginning of array

var colors = ["white","blue"];
colors.unshift("red"); //add red to beginning of colors
// colors = ["red","white","blue"]
Posted by: Guest on July-23-2019
0

how add element at beginning of array in javascript using splice

Array.splice(position,0,new_element_1,new_element_2,...);
Code language: JavaScript (javascript)
Posted by: Guest on April-11-2022

Code answers related to "how to add an item to the beginning of an array js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language