I'm trying to prepend data to an array in VueJs:
number: [
],
this.number.push({
number: 1
})
How do I prepend rather than append?
Unshift:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift
this.number.unshift({number: 1});
You can also pass multiple arguments to add them all:
this.number.unshift({number: 1}, {number: 2});
The return value is the new length of the array:
var foo = [1];
var bar = foo.unshift(2, 3, 4);
//foo = [2, 3, 4, 1]; bar = 4;