I have a array of objects called data in fact it take from API in real code, I can not change its structure. so I want to display data in a table, it has a nested objects called list which contains location and price, I want to display as select option when user change location display own price front of it.
{data.serverTypes.map((Item, Index) => {
return (
<tr key={Index}>
<td>{Item.id}</td>
<td>
<select onChange={(e) => setPrice(e.target.value)}>
{Item.list.map((Location, Idx) => {
return (
<option value={Location.price}>
{Location.location}
</option>
);
})}
</select>
</td>
<td>{price}</td>
</tr>
);
})}
But I can not figure out how can I display each price form each location when I iterate object because I define state outside of loop. for better understanding please see live demo, change select option to see result. already it display price for all, but I want to display each location's price front of it.