API Reference

Underscore.js

Utility library providing functional helpers for collections, arrays, objects, and functions without extending built-ins.

Official Documentation ↗
CompatibilityThis documentation covers version v1. Check the official docs for the latest API surface.

Installation

npmnpm install underscore
pnpmpnpm add underscore

Methods

Overview

Underscore.js is a utility library offering functional helpers for collections, arrays, objects, and functions without modifying built-in prototypes. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.

Core APIs

  • _.map — Produces a new array by applying the iteratee to every element or object value.
  • _.groupBy — Groups values into an object keyed by the iteratee result.
  • _.debounce — Creates a function that postpones invocation until calls stop for the given wait.

Example

const _ = require('underscore');

const names = _.map([{ name: 'a' }, { name: 'b' }], 'name');
console.log(names);

Notes

Underscore never mutates its inputs, which keeps pipelines predictable. Many helpers also accept a property name string as a shorthand iteratee.

Verification

Group an array with groupBy and confirm the result object keys match the distinct values of the chosen property.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://underscorejs.org/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:53:14.598Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

  • You can throw any value to them, but JavaScript will convert the operands to string or number first before performing the actual comparison. (https://underscorejs.org/)
  • Fixes an inconsistency where Array.prototype methods on the Underscore wrapper would error when the wrapped value is null or undefined . (https://underscorejs.org/)
  • Added _.partition , a way to split a collection into two lists of results — those that pass and those that fail a particular predicate. (https://underscorejs.org/)

Security notes

Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://underscorejs.org/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:53:14.598Z.

  • Passing untrusted input to _.template will create a code injection vulnerability in your application or library! (https://underscorejs.org/)
  • Note that if part of your template matches more than one of these regexes, the first will be applied by the following order of priority: (1) escape , (2) interpolate , (3) evaluate . (https://underscorejs.org/)
  • Change Log 1.13.8 — February 19, 2026 — Diff — Docs Fixes a security issue in _.flatten and _.isEqual that, under very specific circumstances, could allow for a Denial of Service (DoS) attack in server applications. (https://underscorejs.org/)

FAQ

How does Underscore differ from Lodash?
Lodash offers more functions and performance optimizations plus modular builds, while Underscore stays smaller and steadier in scope.
Does it mutate input collections?
No. Underscore helpers return new arrays or objects, so the source data is left intact.
How do I use it in the browser?
Underscore ships UMD builds; load underscore.js via a script tag, or import the module with a bundler.