Lodash _.toArray() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Lang

Definition

Converts value to an array. Part of Lodash Lang (stable — not deprecated). Note: not the same as _.castArray — toArray expands array-likes and objects; castArray only wraps.

Pass the value you want to inspect or convert. Read the return type carefully before you use the result.

Syntax

Call _.toArray. Start with this line.

Lodash
_.toArray(value)
CallWhat it does
_.toArray(value)Primary signature.

Prefer import toArray from "lodash/toArray" when you want a smaller bundle.

Library declarations
Lodash
_.toArray(value)

Parameters

ParameterDescription
valueRequired. Value to convert

Return Value

Return ValueDescription
*New Array (always a fresh array for truthy inputs that convert)

Lodash Examples

Example 1 — Official: Object Values

Plain objects become an array of their values.

Lodash
_.toArray({ a: 1, b: 2 });
// → [1, 2]
Try It Yourself

How It Works

  1. Input. Official sample: { a: 1, b: 2 }.
  2. Values. Own enumerable values are collected (like _.values).
  3. Result. [1, 2] — keys are dropped.
  4. Tip. Need key/value pairs? Use _.toPairs instead.

Example 2 — Official: String Characters

Strings become an array of characters.

Lodash
_.toArray('abc');
// → ['a', 'b', 'c']
Try It Yourself

How It Works

  1. Input. Official sample: 'abc'.
  2. Split. Lodash walks Unicode code points.
  3. Result. Three one-letter strings.
  4. vs castArray. _.castArray('abc') would be ['abc'] — one element.

Example 3 — Official: Falsy → Empty

null (and other falsy values) become an empty array.

Lodash
_.toArray(null);
// → []

_.toArray(undefined);
// → []

_.toArray(0);
// → []
Try It Yourself

How It Works

  1. null. Official sample short-circuits → [].
  2. undefined / 0. Same falsy path.
  3. Not wrap. Unlike castArray(null) → [null].
  4. Guard. Do not rely on [] to mean “was null” vs “was empty.”

Example 4 — Map Entries and Set Values

Iterables expand into arrays.

Lodash
_.toArray(new Map([['a', 1], ['b', 2]]));
// → [['a', 1], ['b', 2]]

_.toArray(new Set([1, 2, 2]));
// → [1, 2]
Try It Yourself

How It Works

  1. Map. Iterator yields [key, value] pairs.
  2. Set. Iterator yields unique values.
  3. Copy. Result is a plain array you can index freely.
  4. Related. Detect types with _.isMap / _.isSet.

Example 5 — toArray vs castArray

Same inputs, different jobs — expand vs wrap.

Lodash
console.log(_.toArray('abc'));    // ['a', 'b', 'c']
console.log(_.castArray('abc'));  // ['abc']

console.log(_.toArray({ a: 1 })); // [1]
console.log(_.castArray({ a: 1 })); // [{ a: 1 }]
Try It Yourself

How It Works

  1. toArray. Expands into elements / values.
  2. castArray. Puts the whole value in one slot.
  3. Pick expand. Character lists, object values, iterables → toArray.
  4. Pick wrap. “Always give me an array API” for a scalar → castArray.

Browser & Runtime Support

_.toArray is a Lodash Lang helper available in 4.x (and earlier builds). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native alternatives include Array.from, Object.values, and the spread operator, each covering part of the same job.

✓ Stable · Lodash 4.x

_.toArray()

Available in [email protected] full builds and the lodash/toArray modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.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
_.toArray Lodash 4.x

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import toArray from "lodash/toArray" for smaller builds. For modern engines, Array.from / Object.values / [...iterable] are close cousins.

Frequently Asked Questions

_.toArray(value) converts value into a new array — object values, string characters, Map entries, Set values, or a shallow copy of array-likes. Falsy values become [].
castArray wraps a non-array as [value] (or returns the same array). toArray expands array-likes and objects into element lists — e.g. 'abc' becomes ['a','b','c'], not ['abc'].
Falsy inputs short-circuit to an empty array. That matches the official Lodash example.
Yes. Strings are split by Unicode code points (like the spread operator), so multi-byte characters stay intact instead of breaking into surrogates.
Maps become entry pairs [[key, value], …]. Sets become their values array. Both rely on the iterable protocol.
Use import toArray from "lodash/toArray" or require("lodash/toArray") for tree-shaking friendly bundles. Full build: import _ from "lodash" then _.toArray.

Next: _.toFinite()

Convert a value to a finite number.

_.toFinite() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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