I have the following javascript (typescript) array:
[[1262304000000,0.7537], [1262563200000,0.6951], [1262649600000,0.6925]]
How can I transform it to the following using map operator? (Basically second element of the array has been converted to % value. E.g. 0.7537 to 75.37. However, I am not sure how to access the second element of the array)
[[1262304000000,75.37], [1262563200000,69.51], [1262649600000,69.25]]
>Solution :
const data = [[1262304000000, 0.7537], [1262563200000, 0.6951], [1262649600000, 0.6925]];
const convertedData = data.map(item => {
const timestamp = item[0];
const percent = item[1] * 100; // Convert the second item to a percentage
return [timestamp, percent]; // return both items
});
console.log(convertedData);