Array of arrays in javascript -


is following correct in javascript:

  var candidates = [];   candidates.push(["rand","paul"]);   candidates.push(["hillary","clinton"]); 

where each element in a array of 2 strings.

i pushing a in loop.

additionally can iterate on array follows:

for(var candidate in candidates) {     var first_name = candidate[0]; } 

http://jsfiddle.net/barra/7dver/1/

you should not use in arrays! if array prototype extended run through new functions there keys.

you should do:

var i, first_name; for( = 0; < candidates.length; i++ ) {     first_name = candidates[i][0]; } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -