简体   繁体   中英

Alternatives to underscore.js

I am looking for a JavaScript library that manipulates arrays of objects, mainly for filtering, sorting and grouping/counts.

It seems that underscore.js fits the bill, but I'd be interested to explore other options. Underscore has 60+ functions while I just need a handful.

For example, I would expect some datatable libraries to include such features, but I don't know where to look.

I know this is old but did you look at lodash ? From the site:

A drop-in replacement* for Underscore.js. [...]

Custom builds make it easy to create lightweight versions of Lo-Dash containing only the methods you need. To top it off, we handle all method dependency and alias mapping for you.

看看lazy.js ( http://dtao.github.io/lazy.js/ ) 类似于underscore.js 但由于惰性求值,性能显着提升

It's called JavaScript arr.filter , arr.sort , arr.length .

You can apply any array method on an array, popular ones are filter , map and reduce , You can build more complex operations by combining those.

If you want to iterate over objects use

Object.keys(o).forEach(function (key) {
  var val = o[key];
  ...
});

underscore is useful if you live in an ES3 world, but ES5 has everything you need, all underscore does is add bloat on top of it.

You may want to look into the following two libraries:

lowscore is intended to be a very lightweight underscore:

  • you can require only the functions you need
  • can reduce JS size by roughly 15k minified, or about 50k non-minified.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM