jquery map - assign the return value as a key of the receiving object -
i have:
<img class="images" src="src1"> <img class="images" src="src2"> <img class="images" src="src3"> <img class="images" src="src4"> var pictures = $(".images").map(function(){ return $(this).attr("src"); })
the code above creates new pictures array. can think of efficient way create new pictures object using jquery map function. like:
var pictures[key] = $(".images").map(function(){ var key = $(this).attr("src"); return key; })
... directly assign return value key pictures object. there way?
can't iterate collection?
var picobj = {}; $(".images").each(function() { picobj[$(this).attr("src")] = '...'; });
(demo - print console
)
Comments
Post a Comment