I have this array of (x,y) values and I want to change the form in to(x:,y:). I tried to initialize data to rows and to an emplty array but it didnt work.
var rows = new Array(
Array(0,0),
Array(90,90),
Array(59,70),
Array(65,77),
Array(85,66)
);
for (var i =0; i < rows.length; i++) {
data.push({x: rows[i][0], y: rows[i][1]});
}
how to initialize data array in order to have the wanted array.
asked Sep 29, 2013 at 2:02
user2747249
2 Answers 2
I think you're only missing the declaration of the variable named data:
var data = [];
This JSFiddle works and outputs the right thing: http://jsfiddle.net/UraKr/3/
answered Sep 29, 2013 at 3:06
howrad
1,0862 gold badges13 silver badges32 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
var rows = [[0,0],
[90,90],
[59,70],
[65,77],
[85,66]];
var data = [];
for (var i =0, l = rows.length; i < l; i++) {
data.push({x: rows[i][0], y: rows[i][1]});
}
If you wanted to directly modify rows:
var rows = [[0,0],
[90,90],
[59,70],
[65,77],
[85,66]];
for (var i =0, l = rows.length; i < l; i++) {
rows[i] = {x: rows[i][0], y: rows[i][1]};
}
answered Sep 29, 2013 at 2:06
Michael Benin
4,3222 gold badges25 silver badges15 bronze badges
1 Comment
Michael Benin
what is the intended output of data?
lang-js