How to create an array of object literals in a loop?

I need to create an array of object literals like this: var myColumnDefs = [ {key:”label”, sortable:true, resizeable:true}, {key:”notes”, sortable:true,resizeable:true},…… In a loop like this: for (var i = 0; i < oFullResponse.results.length; i++) { console.log(oFullResponse.results[i].label); } The value of key should be results[i].label in each element of the array. 9 Answers 9

How to use a variable for a key in a JavaScript object literal?

Why does the following work? <something>.stop().animate( { ‘top’ : 10 }, 10 ); Whereas this doesn’t work: var thetop = ‘top’; <something>.stop().animate( { thetop : 10 }, 10 ); To make it even clearer: At the moment I’m not able to pass a CSS property to the animate function as a variable. 16 s 16 … Read more