Underscore.js _.where() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Collection

Definition

Looks through each value in the list, returning an array of all the values that match the key-value pairs listed in properties (official Underscore docs). Stable Collection helper — not deprecated.

Pass the required arguments shown below. Underscore collection helpers usually return a new value — check whether the source is mutated.

Syntax

Call _.where. Start with this line.

Underscore
_.where(list, properties)
CallWhat it does
_.where(list, properties)Primary signature.
_.where(...)Call with the arguments your case needs.

Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.

Library declarations
Underscore
_.where(list, properties)

Parameters

ParameterDescription
listRequired. Collection of objects to search
propertiesRequired. Key-value pairs that must all match

Return Value

Return ValueDescription
*New array of matching values

Underscore.js Examples

Example 1 — Official: Author + Year

Keep plays that match both properties.

Underscore
var listOfPlays = [
  { title: "Cymbeline", author: "Shakespeare", year: 1611 },
  { title: "Hamlet", author: "Shakespeare", year: 1603 },
  { title: "The Tempest", author: "Shakespeare", year: 1611 },
  { title: "Macbeth", author: "Shakespeare", year: 1606 }
];

_.where(listOfPlays, { author: "Shakespeare", year: 1611 });
// → Cymbeline, The Tempest
Try It Yourself

How It Works

  1. Two required pairs: author and year must both match.
  2. Hamlet / Macbeth fail on year.
  3. Cymbeline / The Tempest pass both checks.
  4. Result is a new array — original list unchanged.

Example 2 — Single Property

Match on one field only.

Underscore
var users = [
  { name: "Ada", active: true },
  { name: "Grace", active: false },
  { name: "Alan", active: true }
];

_.where(users, { active: true });
// → Ada, Alan
Try It Yourself

How It Works

  1. Properties: only active: true.
  2. Grace is inactive → skipped.
  3. Ada and Alan match → kept.
  4. Same idea as _.filter(users, _.matcher({ active: true })).

Example 3 — No Matches

Always returns an array — empty when nothing fits.

Underscore
var users = [
  { name: "Ada", active: true },
  { name: "Grace", active: false }
];

_.where(users, { active: true, role: "admin" });
// → []
Try It Yourself

How It Works

  1. Both pairs required — active and role.
  2. No user has role: "admin".
  3. Result: [], not null or undefined.
  4. Safe to chain .length or _.pluck on the result.

Example 4 — _.where vs _.findWhere

All matches vs the first match.

Underscore
var users = [
  { name: "Ada", active: true },
  { name: "Grace", active: false },
  { name: "Alan", active: true }
];

_.where(users, { active: true });
// → [Ada, Alan]

_.findWhere(users, { active: true });
// → Ada   // first only
Try It Yourself

How It Works

  1. _.where keeps scanning and collects every match.
  2. _.findWhere stops at Ada.
  3. Return types differ: array vs object (or undefined).
  4. Pick based on need: list vs single item.

Browser & Runtime Support

_.where ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.

✓ Stable · Underscore 1.x

_.where()

Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.

100% With Underscore 1.x
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.where Underscore 1.x+

Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).

Frequently Asked Questions

_.where(list, properties) returns a new array of all values that contain every key-value pair in properties. Official shape: _.where(listOfPlays, {author: 'Shakespeare', year: 1611}) → matching plays.
_.where is a shorthand for matching object properties. _.filter accepts any predicate function. Equivalent idea: _.filter(list, _.matcher(properties)).
_.where returns all matches as an array. _.findWhere returns only the first match (or undefined) and can stop early.
_.where returns an empty array []. It always returns an array.
No. It checks listed properties with a shallow equality check — nested objects are not deeply compared.
Yes. An item is kept only when it matches every key-value pair you pass.

Next: _.findWhere()

Find the first object that matches a set of key-value pairs.

_.findWhere() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful