The each
function will call a callback once for each element and not group the return values ββas you expect. Instead, you need to save them in a structure that remains after each
method completes.
Try to execute
getNums: function(){ var filter=['20','2']; var result = []; _.each(filter, function(num){ result.push(num); }); return result; }
EDIT
The OP found out that they just want to see if event.target
in the array. In this case, you just want to use the indexOf
method. for instance
getNums: function() { return ['20', '2']; }, buttonClickListener: function(event){ if (this.getNums().indexOf(event.target) >= 0) {
source share