I'm trying to filter an array in javascript, and am struggling when the array is nested.
At the moment, the furthest I've been able to get is filtering a flat array:
var ID = 3
var arr = [{ id : 1, name: "a" }, { id : 2, name: "b" }, { id : 3, name: "c" }]
var result = arr.filter(function( obj ) {return obj.id == ID;});
alert(result[0].name);
Though the above doesn't work if the array looks like this instead:
var arr2 = [
[{ id : 1, name: "a" },{ id : 2, name: "b" }],
[{ id : 3, name: "c" },{ id : 4, name: "d" }]
]
The two examples can be found: https://jsfiddle.net/vjt45xv4/
Any tips for finding the appropriate result on the nested array would be much appreciated.
Thanks!
arrto each item inarr2(since items inarr2are arrays themselves)