Take a look at this function:
//prices is an array of numbers
function mapPrices(prices) {
let newArray = [];
for (let i = 0; i < prices.length; i++) {
newArray.push({ i: prices[i] });
}
return newArray;
}
If I run mapPrices([1,2,3,4]), I expect to get:
[{0: 1}, {1: 2}, {2: 3}, {3: 4}]
instead, I am getting:
[{"i": 1}, {"i": 2}, {"i": 3}, {"i": 4}]
Why?
How can I get what I want?