Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2010/07/29

Solution to the Javascript Object problem

eval()

I should've seen it a while ago.

var jsonA = new Array() ;
var sample_array = [ "foo" , "bar" , "blee" ] ;
for ( var i = 100 ; i <= 290 ; i++ ) {
    for ( j in sample_array ) {
        var k = i * i * (j+1) ;
        k = '"' + k.toString() + '"' ;
        jsonA.push( sample_array[j] + i + " : " + k ) ;
        }
    }
    var json = jsonA.join(" , ") ;
    x = eval( "( { " + json + " } )" ) ;
That is, create an array. put each name:value pair into the array in the name colon value format. Join 'em with commas. Wrap with curly braces ("This is an Object, JS") and parens ("I'm JS. I'm a language. It's my job to have crazy syntax.") Run eval(). I don't show my JSON step, but it's basically taking the params and pushing them back. The interesting thing is, with the data I made up here, the top is between 570 and 585 elements. I don't know if that's an HTTP limitation, an eval() limitation or a jQuery limitation, but I know that once I hit that, the code flakes. Which is interesting.

No comments:

Post a Comment