Exploring a JSON object:
{
"date_price": [
{
"date": "Jan 2000",
"price": 1394.46
},
{
"date": "Feb 2000",
"price": 1366.42
},
{
"date": "Mar 2000",
"price": 1498.58
},
{
"date": "Apr 2000",
"price": 1452.43
}
]
}
In order to iterate through and store each date-price pair in a simple array, you can use the following approach:
var transformation = [];
transformation.push({date: i, price: d})
The challenge arises because the JSON object contains objects inside an array, making it impossible to directly utilize the forEach()
loop on it.