Ember.js Remove Objects From Ember Mutable Arrays

Quang Nguyen
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.

quangtn0018

Just my findings and techniques that I’ve learned from working and doing side projects on all things software engineering related

Quang Nguyen

Written by

Software Engineer

quangtn0018

Just my findings and techniques that I’ve learned from working and doing side projects on all things software engineering related

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade