I am trying to loop Object inside array inside object inside array and I am really confused!
here is my arr:
var arr = [
{
title: "Harry Potter",
categories: [
{
id: 39,
name: "Popular Books"
},
{
id: 3,
name: "Kids"
},
{
id: 79,
name: "All Books"
}
]
},
{
title: "Pride and Prejudice",
categories: [
{
id: 36,
name: "Classic Books"
},
{
id: 3,
name: "Woman"
},
{
id: 79,
name: "All Books"
}
]
}
]
How do I get the title of books that only have category name "Kids"?
Right now all I can think of is:
var find = function(arr){
for(var i=0; i<arr.length; i++){
for(var j=0; j<arr[i].categories; j++){
console.log(arr[i].categories[j].name)
}
}
}
Which is super dirty and does not work anyway. Thank you!