I have an an array as follows:
var data = new Array();
if(j==1){
data['name']=$('input:text[name=full_name]').val();
data['email']=$('input:text[name=email]').val();
data['password']=$('input:password[name=password]').val();
data[' ']=$('input:password[name=retype_password]').val();
}
I want to loop through with this array as follows:
$.each(data,function(index,value){
alert(index + ": " + value );
});
But no alert box is appeared that proves .$each() does not work. How can I fix this issue?
$.each()looks at the type of the object you pass it. If it's an array, then it iterates properties from0to.length - 1. Your array has no such properties so you get no iteration. If you use an object insteadvar data = {}, then.each()will iterate all the properties on that object and you will see what you want. You are misuing an array and should be using an object.