I have a React component. When the user makes a form selection, it retrieves the following object (the content of the object varies depending on the selection made):
Data
jsonObj={
"name":"main",
"type":"meat",
"values":[
["chicken","Roast chicken with vegetables"],
["beef","Beef and Yorkshire pudding"]
]}
Desired results
Here's what I want to display on screen when rendered:
<div>
<label htmlFor="chicken">Roast chicken and vegetables</label>
</div>
<div>
<label htmlFor="beef">Beef and Yorkshire pudding</label>
</div>
My failed attempt!
Object.entries(jsonObj["values"]).map(([val,index]))=>{
return(
<div>
<label htmlFor={val[index][0]}>{jsonSub[key][1]}:</label>
</div>
)
}
The result of this is:
Cannot read property '0' of undefined.
And when I try it in the browser console I get "Uncaught SyntaxError: Malformed arrow function parameter list". Is anyone able to help me get my desired results?!
Many thanks!
Katie
maptakes an array, shouldn't that[val,index]just beval,index? (And it looks like you may be closing your arrow function before it's started with an extra close bracket)