Sorry for my bad English. If I have an array:
const myobj = [
{
id: 1,
name: 'First...'
},
{
id: 2,
name: 'Second...
}];
How can I remove, for example, the object with id
2
? To leave the array only with first object. Which functions should I use? Thanks in advance.
Found solution:
function removeByKey(array, params){
array.some(function(item, index) {
if(array[index][params.key] === params.value){
array.splice(index, 1);
return true;
}
return false;
});
return array;
}
Then
removeByKey(myobj, {
key: 'id',
value: 2
})
http://jsforallof.us/2015/07/08/remove-object-by-key-from-array/