37
rated 0 times
[
44]
[
7]
/ answers: 1 / hits: 29796
/ 13 Years ago, mon, january 9, 2012, 12:00:00
The json object is
var data = [{Parent:1,Child:[4,5,6]},{Parent:2},{Parent:3}]
How can I use underscore.js chain/map/pluck etc... function to get the flatten result
var result = [];
for (var i = 0; i < data.length; i++) {
result.push(data[i].Parent);
if (data.Child != undefined) {
for (var j = 0; j < data[i].Child.length; j++) {
result.push(data[i].Child[j]);
}
}
}
console.log(result) >> //1,4,5,6,2,3
More From » json