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 a new pictures array. Can you think of an efficient way to create a new pictures object using the jQuery map function. I would like to do something like:
var pictures[key] = $(".images").map(function(){
var key = $(this).attr("src");
return key;
})
… directly assign the return value as a key to the pictures object. is there a way?
Can’t you just iterate the collection?
(demo – will print to the
console)