Last active
March 1, 2021 09:37
-
-
Save Nanra/933229c7a464db0f20af45381db92024 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // source: http://stackoverflow.com/questions/16491758/remove-objects-from-array-by-object-property | |
| // source: https://gist.github.com/scottopolis/6e35cf0d53bae81e6161662e6374da04 | |
| // We have an array of objects, we want to remove one object using only the id property | |
| var fruits = [{id:11, name:'Apple', color:'red'}, {id:12, name:'Mangosteen', color:'black'}, {id:13, name:'Banana', color:'yellow'}]; | |
| // Get index of object with id = 12 | |
| var removeAtIndex = fruits.map(function(item) { return item.id; }).indexOf(12); | |
| // remove object | |
| fruits.splice(removeAtIndex, 1); | |
| // Checking Is Existing Value | |
| let isApple = fruits.some(element => element.name === 'Apple'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment