0

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
0

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

0
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

1 Comment

what is the intended output of data?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.