javascript - jQuery "each" -- data... changes... on the other side of the loop -



javascript - jQuery "each" -- data... changes... on the other side of the loop -

so grabbing xml data, , parsing within success function of jquery.ajax call.

var d1 = []; jquery.ajax( { url: ("/charts/quotes/" + name + ".xml"), success: function( info ) { var dstring; var qstring; var d; var q; jquery(data).find("historicalquote").each( function () { dstring = $(this).children("date").text(); qstring = $(this).children("lastclose").text(); d = date.parse(dstring); q = parsefloat(qstring); d1.push( [ d, q ] ); console.log( d1[d1.length-1][0] + ": " + d1[d1.length-1][1] ); /* ^ first log ^ */ } ); console.log( d1.length ); ( var q in d1 ) { console.log(q[0] + ": " + q[1]); /* ^ sec log ^ */ } }, async: false /*the success function must finish before continue.*/ });

now, first log giving me info expect -- "d" long integer, looks might timestamp, , "q" stock quote -- float somewhere around 26.

here's weird thing. outside of each loop ("second log") -- vastly different set of data. starts off with:

(sorry line returns... stack overflow doing odd it)

0: undefined

1: undefined

2: undefined

3: undefined

4: undefined

5: undefined

6: undefined

7: undefined

8: undefined

9: undefined

...and goes on to:

1: 0

1: 1

1: 2

...

1: 9

2: 0

...

3: 9

4: 0

does have way looped through sec time? or way "push" works? in world going on?

q going index of item in d1, not value. want like:

( var q in d1 ) { console.log(d1[q][0] + ": " + d1[q][1]); /* ^ sec log ^ */ }

however using for/in bad thought on numerically indexed array... see link in heikki's comment.

javascript jquery

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -