Ember.js Remove Objects From Ember Mutable Arrays
Sep 3, 2018 · 1 min read
Here’s one of the ways that you should remove objects from Ember’s mutable arrays.
let names = [
{
id: 0,
name: 'John'
},
{
id: 1,
name: 'Jim'
}
]// findBy: returns the first item that match arguments
let nameToRemove = names.findBy('name', 'Jim')if (!nameToRemove) {
// deal with error
return
}names.removeObject(nameToRemove)
The reason we’re using findBy is to guarantee that the object to remove exists. It acts like a safety check to make sure there is something to remove, if not then we can deal with it accordingly.

