Consider the following array:
var booksStudents = [
{
name: "David",
books: {
"fantasy": 23,
"action": 31,
"thriller" 21,
}
},
name: "Paul",
books: {
"fantasy": 17,
"action": 13,
"thriller" 23,
}
},
name: "Zoe",
books: {
"fantasy": 5,
"action": 7,
"thriller" 28,
}
}];
I am trying to create an array of objects with each person's name and the total number of books they have. While I am familiar with using reduce on simple arrays, I am struggling with this array of objects. I considered using .map
and .reduce
, but so far I haven't found a suitable solution.