Skip to content

Instantly share code, notes, and snippets.

@arisawali2014
Last active June 23, 2021 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arisawali2014/4be5e7379b591f91718dfbe420ff449f to your computer and use it in GitHub Desktop.
Save arisawali2014/4be5e7379b591f91718dfbe420ff449f to your computer and use it in GitHub Desktop.
Removing object item from array in javascript
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"}
];
function RemoveNode(id) {
return data.filter(function(emp) {
if (emp.id == id) {
return false;
}
return true;
});
}
var newData = RemoveNode("1");
document.write(JSON.stringify(newData, 0, 4));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment