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}
];
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}
];
Maybe something like this will do the trick:
var values = [1,2,3];
var _dict = [];
for (var i = 0; i < values.length; i++) {
_dict.push( {x: i, value: values[i]} );
}
for ... in loop for iterating through arrays. 3. The x and y should be separate properties. Define the _dict as an array, iterate properly and then use the Array.prototype.push method for pushing an object into the array._dict variable as an array. var _dict = [];