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.

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/

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]};
} 

1 Comment

what is the intended output of data?

Your Answer

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