I am trying to search a object and remove from json array
my json array of object looks like
var data = [{
{id: "1", name: "Snatch", type: "crime"},
{id: "2", name: "Witches of Eastwick", type: "comedy"},
{id: "3", name: "X-Men", type: "action"},
{id: "4", name: "Ordinary People", type: "drama"},
{id: "5", name: "Billy Elliot", type: "drama"},
{id: "6", name: "Toy Story", type: "children"}
}];
What I am try to achieve is if I have a object with Id=1
I can search the array match it with array and remove it from the array.
I am trying this by below code
function RemoveNode(id)
{
data.forEach(function (emp) {
if(emp.Id == id)
{
delete emp;
}
}
}
I am not able to get it work, kindly suggest a better way to do this
datashould be either an array (var data = [...]) or an object with a property (var data = {arr:[..]}). Currently it is an object without a property name!