-
Star
(143)
You must be signed in to star a gist -
Fork
(36)
You must be signed in to fork a gist
-
-
Save scottopolis/6e35cf0d53bae81e6161662e6374da04 to your computer and use it in GitHub Desktop.
// we have an array of objects, we want to remove one object using only the id property | |
const apps = [{id:34,name:'My App',another:'thing'},{id:37,name:'My New App',another:'things'}]; | |
// get index of object with id of 37 | |
const removeIndex = apps.findIndex( item => item.id === 37 ); | |
// remove object | |
apps.splice( removeIndex, 1 ); | |
/*** Code above updated 7/21 with findIndex, a much faster method. Old code below for reference. ***/ | |
// source: http://stackoverflow.com/questions/16491758/remove-objects-from-array-by-object-property | |
// get index of object with id:37 | |
var removeIndex = apps.map(function(item) { return item.id; }).indexOf(37); | |
// remove object | |
apps.splice(removeIndex, 1); |
apps.splice( apps.findIndex(a => a.id === 37) , 1)
Super cool
Original solution also Awesome!!
It was Great! saved a lot of time.
This is cool. Thank you.
Been searching for a simple solution for hours. Thank you
Thank you! I will be using this forever :-)
Thanks. This will help me on my todo list delete function. have been searching for this
Many thanks
Great!
Thank you!
+1
Bless Up
apps = apps.filter(a => a.id !== 37);
It takes too much time and also contains extra space.
although perfectly fine !!!
Thanks!
It can be done easier now
apps.map(item => item.id).indexOf(37)
thank u solve my problem!
Thank you.
thank you exactly what I was looking for
Thanks!
Cool man thanks !!
You save my time after 2 Hours of searching...Thank
excellent, thanks!
Awesome! Thank you.
Thanks Buddy
thank you
Ty
Very useful thankyou machi !
Thanks a lot, It was Great.