Take a look at the DOCS on collection.. You can use the collect method on any array to convert it to collection then use Laravel in built collection methods like slice and pull or where to remove by key...
Jan 18, 2017
11
Level 51
How to remove an item from a list with given ID in VueJS
Hi, I need to delete an item in list in VueJS when I have the id
My list looks like:
list : [
{id: 5, name: Item1},
{id: 10, name: Item2}
]
I have a method
deleteItem(itemID){}
How can I delete an item from 'list' where id = itemID
I know it shoul look something like:
this.questions.splice(id, data);
But not sure how exactly. Thanks for your help.
Level 1
when using {{splice}} the first argument is an index of array, not element itself
your code should be
let i = list.map(item => item.id).indexOf(itemID) // find index of your object
list.splice(i, 1) // remove it from array
@m7vm7v thanks. i made an update to the code.
9 likes
Please or to participate in this conversation.