You can create an array of src attributes more directly using map() :
var tn_array = $("#thumbnails img").map(function() { return $(this).attr("src"); });
Edit: tn_array is an object, not a strict Javascript array, but it will act like an array. For example, this is a legal code:
for (int i=0; i<tn_array.length; i++) { alert(tn_array[i]); }
However, you can call get() , which will make it a strict array:
var tn_array = $("#thumbnails img").map(function() { return $(this).attr("src"); }).get();
How do you say the difference? Call:
alert(obj.constructor.toString());
The first version will be:
function Object() { [native code] }
Second:
function Array() { [native code] }
cletus Mar 01 '10 at 10:11 2010-03-01 10:11
source share