, :
var listWidth = [];
$('ul li').each(function(){
listWidth.push($(this).width());
});
console.log(listWidth);
:
var listWidth = {};
$('ul li').each(function(){
listWidth[$(this).attr('id')] = $(this).width();
});
console.log(listWidth);
, ({ id1: width, id2: width, etc...}, ).
In the above code example, the problem was that when returning the width, it returned to the each function (which probably just dropped it), but listWidthwas the return value of the each function and not the anonymous function inside (so since each function returns jQuery object, i.e. what was assigned to listWidth).
source
share