Underscore.js

Underscore.js
Video _.some

Underscore.js

Underscore is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects. It’s the answer to the question: “If I sit down in front of a blank HTML page, and want to start being productive immediately, what do I need?” … and the tie to go along with jQuery’s tux and Backbone’s suspenders.

Underscore provides over 100 functions that support both your favorite workaday functional helpers: map, filter, invoke — as well as more specialized goodies: function binding, javascript templating, creating quick indexes, deep equality testing, and so on.

A complete Test Suite is included for your perusal.

You may also read through the annotated source code. There is a modular version with clickable import references as well.

You may choose between monolithic and modular imports. There is a quick summary of the options below, as well as a more comprehensive discussion in the article.

Enjoying Underscore, and want to turn it up to 11? Try Underscore-contrib.

The project is hosted on GitHub. You can report bugs and discuss features on the issues page or chat in the Gitter channel.

You can support the project by donating on Patreon. Enterprise coverage is available as part of the Tidelift Subscription.

Underscore is an open-source component of DocumentCloud.

v1.13.6 Downloads (Right-click, and use “Save As”)

ESM (Development) 65.9 KB, Uncompressed with Plentiful Comments (Source Map) ESM (Production) 8.59 KB, Minified and Gzipped (Source Map) UMD (Development) 68.4 KB, Uncompressed with Bountiful Comments (Source Map) UMD (Production) 7.48 KB, Minified and Gzipped (Source Map) Edge ESM Unreleased, current master, use by your own judgement and at your own risk Edge UMD Unreleased, current master, use if you’re feeling lucky

v1.13.6 CDN URLs (Use with <script src=”…”></script>)

  • https://cdn.jsdelivr.net/npm/[email protected]/underscore-umd-min.js
  • https://cdn.jsdelivr.net/npm/[email protected]/underscore-esm-min.js
  • https://unpkg.com/[email protected]/underscore-umd-min.js
  • https://unpkg.com/[email protected]/underscore-esm-min.js
  • https://pagecdn.io/lib/underscore/1.13.6/underscore-umd-min.js
  • https://pagecdn.io/lib/underscore/1.13.6/underscore-esm-min.js
  • https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.13.6/underscore-umd-min.js
  • https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.13.6/underscore-esm-min.js

In most cases, you can replace the version number above by latest so that your embed will automatically use the latest version, or stable if you want to delay updating until an update has proven to be free of accidental breaking changes. Example:https://cdn.jsdelivr.net/npm/underscore@latest/underscore-umd-min.js

Package Installation

  • Node.js npm install underscore
  • Meteor.js meteor add underscore
  • Bower bower install underscore

If you are hardcoding the path to the file within the package and you are unsure which build to use, it is very likely that you need underscore-umd.js or the minified variant underscore-umd-min.js.

Monolithic Import (recommended)

  • ESM import _, { map } from ‘underscore’;
  • AMD require([‘underscore’], …)
  • CommonJS var _ = require(‘underscore’);
  • ExtendScript #include “underscore-umd.js”

Modular Import

  • ESM import map from ‘underscore/modules/map.js’
  • AMD require([‘underscore/amd/map.js’], …)
  • CommonJS var map = require(‘underscore/cjs/map.js’);

For functions with multiple aliases, the file name of the module is always the first name that appears in the documentation. For example, _.reduce/_.inject/_.foldl is exported from underscore/modules/reduce.js. Modular usage is mostly recommended for creating a customized build of Underscore.

Engine Compatibility

Underscore 1.x is backwards compatible with any engine that fully supports ES3, while also utilizing newer features when available, such as Object.keys, typed arrays and ES modules. We routinely run our unittests against the JavaScript engines listed below:

  • Chrome 26-latest
  • Edge 13, 18 and latest
  • Firefox 11-latest
  • Internet Explorer 9-11
  • Node.js 8-latest LTS
  • Safari 8-latest

In addition:

  • We have recent confirmation that the library is compatible with Adobe ExtendScript.
  • There is support code present for IE 8, which we will retain in future Underscore 1.x updates.
  • Patches to enhance support for other ES3-compatible environments are always welcome.

Underscore 2.x will likely remove support for some outdated environments.