javascript - Looping through a multidimensional array with jQuery -


i trying use jquery's each function loop through array below. goal find both key ("name") , use underlying array values output in webpage.

array (     [e-mail] => array         (             [0] => e-mail address spelled incorrectly             [1] => error annoy further         ) ) 

there no associative arrays in javscript, means :

array (     [e-mail] => array         (             [0] => e-mail address spelled incorrectly             [1] => error annoy further         ) ) 

you not use array, object instead, , object contain array of messages. here example :

var data = {    email : [       "your e-mail address spelled incorrectly",       "another error annoy further"    ] }; 

now, loop arround data.email array can use $.each of jquery or array.prototype.foreach native method

data.email.foreach(function (item, index) {     console.log(item); }); 

using $.each :

$.each(data.email, function (index, item) {     console.log(item); }); 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -