Put .each values in an array

Hello forums,

I have this jquery code.

$("#myselect select ").each(function () {
	   var ids = $(this).attr("id");
	   //alert (ids);
		 });

I want to put all the values of var id in my loop inside an array. How do I do that?

Thanks

Very simple, there are a couple of ways to create a new array with JavaScript but i personally prefer the shortest way possible. Below is an example of how you can push the id value into an array.

var myArray = [];

$('#myselect select').each(function() {
    // Push the id in "myArray"
    myArray.push($(this).attr('id'));
});

If you want to see the array after the loop is complete i recommend you try Firebug for Firefox as it has some of the best console logging tools i have found.

Firebug and Logging : Firebug

Thanks SgtLegend that works :cool:

No problem