Push object to array of objects on click

So I have a vue.js app that has objects being rendered in a single list with two columns as shown below:
enter image description here

When I click on the "X" on the object, I get the following return:
enter image description here

So the method is shown below:

remove(x) {
    console.log(this.$data.list.selected[x]);
    console.log(this.$data.list.available);
    console.log(x);
},

The this.$data.list.selected[x] is the object in the left column, and the array of objects is in this.$data.list.available.

What would be the best way for me to remove the object inside my method and then push it to the end of the array in this.$data.list.available – All help would be appreciated!

25 thoughts on “Push object to array of objects on click”

  1. If x is the index of the item in this.$data.list.selected[], you could splice the item to remove it from the original array, and push it into this.$data.list.available[]:

    this.$data.list.available.push(this.$data.list.selected.splice(x, 1))
    
    Reply

Leave a Comment