Is there a more elegant way to write this kind of function without having to initialize an array:
function getStuff () {
var some_array= [];
$("#some-id ul li span.key").each(function() {
some_array.push($(this).text());
});
return some_array;
}
jQuery.mapFiddle
Performance-wise, the difference is minimal. Also, as noted by Lix, choose the method which you find more readable and maintainable. In the end, both will end up creating an array, iterating over elements, pushing string values to the array and returning the array.