Created
February 20, 2020 06:06
-
-
Save vijjusri14/5095a8747406103ab1caa87fb4f7a07b to your computer and use it in GitHub Desktop.
Filter object array with object id in 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
| function filteredById(m) { | |
| return this.id === m.id; | |
| } | |
| var x = [ | |
| { name: "Apple", id: 123 }, | |
| { name: "Ball", id: 124 }, | |
| { name: "Cat", id: 125 } | |
| ]; | |
| var y = { id: 123 }; | |
| var z = x.filter(filteredById, y); | |
| console.log({ name:z[0].name }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment