I get an array of objects representing books. Book has nested Chapters and each chapter has nested Pages. I am trying to reach pages using where and/or chain and name of the chapter but don't know how to reference pages to iterate and get name and keyword. None of my approaches worked and obviously I am missing a key understanding.
var getPages = function(book, n) {
_.chain(book.chapters).where({name:n})...how do I refer pages array from here?;
or
_.select(_.where(book.chapters,{name:n}), function(p) {
return p.keyword + p.name;
};
};
Nested Data:
{
"name": "Javascript for Dummies",
"chapters": [
{
"name": "Introduction",
"status": "passed",
"pages": [
{
"name": "page 10",
"keyword": "objects",
"status": "passed"
},
{
"name": "page 40",
"keyword": "methods",
"status": "failed"
},
{
"name": "",
"keyword": "",
"status": ""
}
]
},
{
"name": "Data Types",
"status": "passed",
"pages": [
{
"name": "page 33",
"keyword": "Strings",
"status": "passed"
},
{
"name": "",
"keyword": "",
"status": ""
},
{
"name": "",
"keyword": "",
"status": ""
}
]
}
],
"status": "failed"
}