My data structure:
const obj = {
"data": [
{
"id": 1,
"name": "Genre 1",
"books": [
{ "id": 1, "name": "book 1" },
{ "id": 2, "name": "book 2" },
{ "id": 3, "name": "book 3" }
]
},
{
"id": 2,
"name": "Genre 2",
"books": [
{ "id": 1, "name": "book 1" },
{ "id": 2, "name": "book 2" },
{ "id": 3, "name": "book 3" }
]
},
{
"id": 3,
"name": "Genre 3",
"books": [
{ "id": 1, "name": "book 1" },
{ "id": 2, "name": "book 2" },
{ "id": 3, "name": "book 3" }
]
}
]
};
If given an id, how can I assign the appropriate array of books to a 1 const?
var <whatever> = [....]orvar <whatever> = { "data": [...] }. If you updated this, you could get better responses for how to find an object within an array that is the value to the key calleddata(the way I think you intended this to be, OR the object that has the correctidin a variable called data with an array as it's value (which some might argue would be simpler). Either way, it would help :)