I have a JSON coming as a response and I need to map over it using React.
The JSON itself is an array and it also contains an array and I need to map over all the objects and somehow know the variable names.
This is my JSON. Is there a way to do that?
[
{
"name":{
"english":"name1",
"finnish":" name2"
},
"imageList":[
"xyxyxyxy"
]
}
]
So i have tried mapping over it using this:
{this.state.imageData.map((item, key) =>
<p>Device name: {item.name}, En device name: {item.name.english}</p>
)}
But I get the error that it doesnt know what "english" is:
Objects are not valid as a React child (found: object with keys {english, finnish}). If you meant to render a collection of children, use an array instead.
I get the JSON as a response from fetch:
let images = await fetch(`myurl` + id);
return await images.json();
What I need is to be able to map over each object in the list and then also map over data in the imageList.
So like in the example above I would like to do something like:
this.state.imageData.map((item, key) =>
<p>Device name: {item.name}, En device name: {item.name.english}</p>
for(image: item.imageList){
console.log(image)
}
Object.keysto get the value of keys of object.{item.name}with this?{item.name}and see if{item.name.english}prints?