Skip to content

Instantly share code, notes, and snippets.

@juanbrusco
Last active January 25, 2019 15:19
Show Gist options
  • Save juanbrusco/ff01786e381f71227f78a81a23b0dcd9 to your computer and use it in GitHub Desktop.
Save juanbrusco/ff01786e381f71227f78a81a23b0dcd9 to your computer and use it in GitHub Desktop.
Remove Object From Array - Javascript
// non destructive filter > noJohn = John removed, but someArray will not change
let someArray = getArray();
let noJohn = someArray.filter( el => el.name !== "John" );
// destructive splice /w findIndex
let someArray3 = getArray();
someArray3.splice(someArray3.findIndex(v => v.name === "John"), 1);
function getArray() {
return [ {name: "Kristian", lines: "2,5,10"},
{name: "John", lines: "1,19,26,96"},
{name: "Brian", lines: "3,9,62,36"} ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment