I'm trying to print my cart status in a JSX table without success.
I have this Object output in state
Chrome Console:
{
"cartItems": {
"5": {
"id": 5,
"name": "Aut assumenda.",
"price": 526,
"quantity": 1,
"attributes": [],
"conditions": [],
"associatedModel": {
"id": 5,
"name": "Aut assumenda.",
"description": "Nihil quisquam hic voluptatem consequuntur nemo et amet rerum.",
"price": "526",
"created_at": "2020-11-25T22:43:32.000000Z",
"updated_at": "2020-11-25T22:43:32.000000Z"
}
},
"6": {
"id": 6,
"name": "Non est consequatur.",
"price": 453,
"quantity": 1,
"attributes": [],
"conditions": [],
"associatedModel": {
"id": 6,
"name": "Non est consequatur.",
"description": "Facilis itaque ut reiciendis blanditiis maxime corrupti voluptatem.",
"price": "453",
"created_at": "2020-11-25T22:43:32.000000Z",
"updated_at": "2020-11-25T22:43:32.000000Z"
}
}
}
}
I want to print the object properties with Object.keys.map() method like so:
{
Object.keys(cartItems).map((item, i) => {
return ( <
tr key = {i} >
<td scope="row">{item.name}</td>
<td>{item.price}</td>
<td>{item.quantity}</td>
</tr>
);
})
}
Yet I cannot correctly print my cart table. I have been playing around with console log and I can't find the solution for this. It does surely have a simplem solution but I'm new to Javascript it is not evident for me in relation to my expertise.
If I console.log(item)
inside the map method I'd get the object names which in this case are 5
and 6
.
Thank you all