I have a need to add or prepend elements at the beginning of an array.
For example, if my array looks like below:
[23, 45, 12, 67]
you have an array: var arr = [23, 45, 12, 67];
var arr = [23, 45, 12, 67];
To add an item to the beginning, you want to use splice:
splice
var arr = [23, 45, 12, 67]; arr.splice(0, 0, 34) console.log(arr);