Last active
January 25, 2019 15:19
-
-
Save juanbrusco/ff01786e381f71227f78a81a23b0dcd9 to your computer and use it in GitHub Desktop.
Remove Object From Array - Javascript
This file contains hidden or 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
// 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