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
Post a Comment