[Vuejs]-How do I split up an array while still selecting all items?

0👍

It outputs the entire fruit items because you are pushing the whole array into the basket array, not the actual items. Saying basket is an array of array, not an array of fruits.

// Instead of this
this.basket.push(this.fruits); // [['Orange', 'Apple']]

// Use array destructuring
this.basket.push(...this.fruits); // ['Orange, 'Apple']
// Or concat
this.basket.concat(this.fruits); // ['Orange, 'Apple']

Leave a comment