使用 Underscore.js

each

_.each(list, iteratee, [context])

1
2
_.each({one: 1, two: 2, three: 3}, (value, key, list) => {console.log(value, key, list)});
_.each([1, 2, 3], (element, index, list) => {console.log(element, index, list)});

find

groupBy

1
2
3
_.groupBy([1.3, 2.1, 2.4], function(num){ return Math.floor(num); });

_.groupBy(['one', 'two', 'three'], 'length');