let’s compare native
Andrey Evstropov
1

var arr = [{ num: 1, foo: true }, { num: 2, foo: false }, { num: 3, foo: true }, { num: 4, foo: true }];
// Underscore ES5/ES6
_.chain(arr).filter({ foo: true }).map('num').value(); // [1,3,4]
// ES5
arr.filter(function(arrObj) {
return arrObj.foo;
}).map(function(arrObj){
return arrObj.num;
}); // [1,3,4]
// ES6
arr.filter(arrObj => arrObj.foo).map(arrObj => arrObj.num); // [1,3,4]
// oh wait, don't want it to crash if it's null
if(arr) {
arr.filter(arrObj => arrObj.foo).map(arrObj => arrObj.num); // [1,3,4]
}

So ok maybe ES6 is better if you’re only use case for `Array.Prototype` and `underscore` was `map` and `filter`.

var arr = [{ num: 1, sort: 4 }, { num: 2, sort: 3 }, { num: 3, sort: 2 }, { num: 4, sort: 1 }];
// Array not mutated
_.chain(arr).sortBy('sort').map('num').value(); // [4,3,2,1]
// Oh no! what happened to arr?
arr.sort((aObj, bObj) => {
return aObj > bObj ? 1 : -1;
}).map(arrObj => arrObj.num); // [4,3,2,1]
// Array not mutated version
arr.slice().sort((aObj, bObj) => {
return aObj > bObj ? 1 : -1;
}).map(arrObj => arrObj.num); // [4,3,2,1]

lodash = consistent api across many situations. Can you reduce a few characters in a couple of places with native? Sure. Have fun.

Like what you read? Give Paul Falgout a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.