how to find and remove object from array in javascript
// we have an array of objects, we want to remove one object using only the id property
var apps = [{id:34,name:'My App',another:'thing'},{id:37,name:'My New App',another:'things'}];
// get index of object with id:37
var removeIndex = apps.map(function(item) { return item.id; }).indexOf(37);
// remove object
apps.splice(removeIndex, 1);const array = [
{ id: 1, name: 'serdar' },
{ id: 5, name: 'alex' },
{ id: 300, name: 'brittany' }
];
const idToRemove = 5;
const filterArray = array.filter((item) => item.id !== idToRemove); //ES6
// [
// { id: 1, name: 'serdar' },
// { id: 300, name: 'brittany' }
// [var id = 88;
for(var i = 0; i < data.length; i++) {
if(data[i].id == id) {
data.splice(i, 1);
break;
}
}someArray.splice(x, 1);var id = 88;
for(var i = 0; i < data.length; i++) {
if(data[i].id == id) {
data.splice(i, 1);
break;
}
}
Also in JavaScript:
- install php7 runtime brackets
- mongodb replace string
- : not foundram Files/nodejs/npm: 3:
- electron send message from renderer to main
- javascript crash course
- if i pass an object to a function is it the same object javascript
- inline if else javascript
- javascript remove element from array
- firebase contains query realtime
- javascript create range with a loop
- javascript greater than or equal to
- How to make add cooldowns to a command in discord.js
- npm google map api react
- How to remove options from selectlist in javascript?
- javascript array contains object
- json stringify close circle
- formidable express
- javascript setattribute onclick function with parameters
- return string from javascript function
- how to empty form after submit react
- jQuery change select value
- mongodb nodejs connect localhost
- javascript loop over the alphabet and return the vowels
- jquery datatable