I would like to convert and array in this format
var values = [1,2,3];
To an array in this format
var data = [
{x: 0, value: 1},
{x: 1, value: 2},
{x: 2, value: 3}
];
You could simply use the Array.prototype.map
method:
var data = values.map(function(el, i) {
return {
x: i,
value: el
}
});
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments