I'm learning about fetch()
and am struggling to overcome an issue. I have some JSON data I am fetching, but the key is the "parent" of each item, eg it looks like:
products
p1
description:"Lorem Ipsum"
name:"some product"
price:9.99
p2
description:"Dolar sit amet"
name:"another product"
price:15.5
I'd like to .map()
this data into a new array, as such:
const newData= data.results.map(item => {
return {
id: item.id,
name: item.name,
description: item.description,
price: item.price
};
});
But I don't understand how I can iterate through each item and save it's ID without a key.
Would anyone know how I could do this?