[Vuejs]-Push adds array to array instead of elements

1๐Ÿ‘

โœ…

You could use spread operator to concatenate the original array with the new one :

this.elements =[...this.elements, ...response.data]

2๐Ÿ‘

You can use push with spread operator:

this.elements.push(...response.data)

E.g.

const arr1 = [1, 2, 3];
const arr2 = [12, 13, 14];
arr1.push(...arr2);
console.log(arr1);

Leave a comment