views:

19

answers:

1

I have a set of text boxes in which the user inputs an email address into each one. I want to loop around these and build an array of them. How do I do it?

var emailAddresses = new Array();
 $(".email_address").each(
        function() {
                    //add this $(this).val() emailAddresses                                                                   
        }
 );
+1  A: 
var emailsArr = $('.email_address').map(function(i,n) {
    return n.value; //or $(n).val() or $(n).attr('value')
}).get();

See $.map for an awesomely concise way to do this sort of thing. get converts the returned collection into an array. Hope that helped.

karim79
Thanks, I through there would be a nice shorthand way of doing it.
Dan