Please see my code:
function foo() {
var h = "start";
$.each(some_array_of_objects, function() {
var name = 'middle';
h += name;
});
h += "end";
alert(h);
}
I expect to see accumulated string in my alert but instead of this I got string with a lot of [object Object] strings. Is that possible to accumulate h variable in above way WITHOUT USING global variables?
There’s no need to use jQuery to loop through arrays / object, just use a
forloop for arrays, and afor-infor objects.This will work in your case: