I am doing a get request on JS and with the json reponse i want to get some values, for example product and color, but i don't know how i can go more deeper on the next levels of the objects of the Json.
the Json:
{
"items": {
"1man": {
"312favorites": {
"155description": {
"color": "red",
"price": 2.76666
}
}
}
}
}
I just can go until the 1man level i don't know how to get the next levels, my code until now
console.log(response.data.items['1man']);
If i try for example console.log(response.data.items['1man'].312favorites
i get error on VScode, i want go to until the color value...
Does someone can help me here?
CodePudding user response:
You have to do it this way:
response.data.items['1man']['312favorites']['155description'].color
The reason is that the key has some numbers, and it can't be accessed with Dot notation because it has to be without any numbers or special characters that's why you must use Bracket notation .