I want to call each() on the resulting array of another function that I call.
Why can't I do:
callMethodThatReturnsAnArray().each(function () {
...
});
I get a callMethodThatReturnsAnArray(...).each is not a function error.
I want to call each() on the resulting array of another function that I call.
Why can't I do:
callMethodThatReturnsAnArray().each(function () {
...
});
I get a callMethodThatReturnsAnArray(...).each is not a function error.
each() is jQuery for DOM elements - what are you doing exactly? For plain Javascript, you'll want to use forEach() or map()
Array has forEach method not each. Use
callMethodThatReturnsAnArray().forEach(function(entry) {
// ...do whatever you want to do
});
If you want to use each, Jquery has method
jQuery.each(array, callback )
So you can write code something like.
$.each(callMethodThatReturnsAnArray(), function(index, value){// do whatever you want to do.});