I have the following object array:
var list = [{
"id": 119,
"files": []
}, {
"id": 126,
"files": [{
"id": 9,
"filename": "test1.docx",
}, {
"id": 10,
"filename": "test2.docx",
}]
}]
How can update the list by deleting the file with a specific id (file ids are unique) So for example I want to delete the file with id of 10 .
This is what I've tried so far using underscore but it doesnt work:
_.each(list.item, function(item, idx) {
if (_.findWhere(item.files, { id: 10 })) {
//remove file from files array
files.splice(idx, 1);
}
});
I want to update the list by deleting file object with a particular id
All the solutions so far create a copy of the original. Is there any way to simply splice it out from the original list?
If I have both the item id and file id then how can I delete the file object?, do you mean to delete the files with the supplied id and file id independently or files with a given item id?