Wednesday, 2 October 2013

Underscore/Lo-Dash _.each not returning array

Underscore/Lo-Dash _.each not returning array

I was initially trying to do this:
var array = ['A','B','C'];
array = _.each(array, function(item) { return item + '+' });
to get this:
['A+','B+','C+'];
but _.each does not seem to return a function.
I eventually settled on this:
var array = ['A','B','C'];
newArray = [];
_.each(array, function(item) {
newArray.push(item + '+');
});
but it seems pretty clunky by comparison.
Am I using _.each incorrectly, or is there another function I should be
using?

No comments:

Post a Comment