Lodash _.head() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Array

Definition

Gets the first element of array. Empty arrays return undefined. Alias: _.first. Part of Lodash 4.x Array.

Pass the required arguments shown below. Lodash Array helpers usually return a new value — check whether the source array is mutated.

Syntax

Call _.head on an array. Start with this line.

Lodash
_.head(array)
CallWhat it does
_.head(array)Primary signature.
_.head(array)Call with an array argument.

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

Library declarations
Lodash
_.head(array)

Parameters

ParameterDescription
arrayRequired. Collection to read from

Return Value

Return ValueDescription
*First element, or undefined

Lodash Examples

Example 1 — Official: First Element

Read the value at index 0.

Lodash
_.head([1, 2, 3]);
// → 1
Try It Yourself

How It Works

  1. Source. Official sample: [1, 2, 3].
  2. First slot. Index 0 holds 1.
  3. Return. _.head returns that value.
  4. No change. The array still contains three numbers.

Example 2 — Official: Empty Array

No elements means there is nothing to return.

Lodash
_.head([]);
// → undefined
Try It Yourself

How It Works

  1. Empty source. Length is 0.
  2. No first slot. Lodash returns undefined.
  3. Safe. It does not throw — check before using the value.
  4. Tip. Use a default: _.head(arr) ?? fallback.

Example 3 — Alias _.first

_.first is the same function as _.head.

Lodash
_.first([1, 2, 3]);
// → 1

_.head === _.first;
// → true  (same function in the full build)
Try It Yourself

How It Works

  1. Alias. Docs list _.first → head.
  2. Same result. _.first([1,2,3]) returns 1.
  3. Pick a name. Prefer one style in a codebase for consistency.
  4. Imports. lodash/first and lodash/head both work.

Example 4 — First String in a List

Works the same for any element type — here, three words.

Lodash
_.head(["alpha", "beta", "gamma"]);
// → "alpha"
Try It Yourself

How It Works

  1. List of words. Indexes 0 … 2.
  2. Peek. _.head returns "alpha".
  3. Rest stay. "beta" and "gamma" remain in the array.
  4. Use. Good for queues, menus, or “show first item” UI.

Example 5 — _.head vs _.last

Opposite ends of the same array.

Lodash
var nums = [10, 20, 30];

_.head(nums);  // → 10
_.last(nums);  // → 30
Try It Yourself

How It Works

  1. Head. First index → 10.
  2. Last. _.last reads the other end → 30.
  3. Pair. Together they cover both ends without index math.
  4. Middle. For an arbitrary index, use _.nth.

Browser & Runtime Support

_.head (alias _.first) is a Lodash 4.x Array helper. It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 4.x

_.head()

Available in [email protected] full builds and the lodash/head (or lodash/first) 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
_.head Lodash 4.x+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import head from "lodash/head" for smaller builds. Native alternatives: arr[0] or Array.prototype.at(0).

Frequently Asked Questions

_.head(array) returns the first element of array. For an empty array it returns undefined. It does not change the array.
Yes. _.first is an alias for _.head — same implementation, choose whichever name reads best.
No. It only reads the first slot and returns that value (or undefined).
For a real array they match. _.head also coerces many array-like values and returns undefined safely when the collection is empty or nullish.
On ordinary arrays they agree. _.nth also supports negative indexes for other positions; use head when you only need the first element.
Use import head from "lodash/head" or import first from "lodash/first". Full build: import _ from "lodash" then _.head.

Next: _.indexOf()

Find the index of the first occurrence of a value in an array.

_.indexOf() 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