I call api and have a object:
const body = { data: { book: [ { "name": "math", "class": 8, "level": 2 }, { "name": "math", "class": 10, "level": 2} ]} }
Now i want to get array
[ { "name": "math", "class": 8, "level": 2 }, { "name": "math", "class": 10, "level": 2} ]
But I get const books = body.data.book and console.log(books) and I have undefined book. You can help me?
CodePudding user response:
Could it be the data needs to be stored as a .json() before being accessed?
CodePudding user response:
Just tried this and the console log returns the correct array for me. Is there more code to this?
