Last active
June 23, 2021 04:29
-
-
Save arisawali2014/4be5e7379b591f91718dfbe420ff449f to your computer and use it in GitHub Desktop.
Removing object item from array in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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