47
rated 0 times
[
54]
[
7]
/ answers: 1 / hits: 9511
/ 10 Years ago, tue, july 15, 2014, 12:00:00
I have data-structure like this:
[
{
name: AAAA,
children: [
{name: vvv, id: 3},
{name: vvv22, id: 4}
]
},
{
name: BBBB,
children: [
{name: ggg, id: 5},
{name: ggggv22, id: 6}
]
},
]
And I want to find and return child with given ID. How to achieve this using Underscore.js?
My current realisation without using Underscore:
for (var i = 0; i < data.length; i++) {
var dataItem= data[i];
for (var j = 0; j < dataItem.children.length; j++) {
var child = dataItem.children[j];
if (child .id == id) {
return child;
}
}
}
More From » underscore.js