EN
JavaScript - add item at the beginning of array
3
points
In this article, we would like to show you how to add item at the beginning of array using JavaScript.
Quick solution:
array.unshift(item); // prepends item
Practical example
// ONLINE-RUNNER:browser;
var array = ['A', 'B'];
array.unshift('C'); // prepends item
console.log(array); // ['C', 'A', 'B']