Lodash _.initial() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Array

Definition

Gets all but the last element of array. Returns a new slice — the source is unchanged. 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 _.initial on an array. Start with this line.

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

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

Library declarations
Lodash
_.initial(array)

Parameters

ParameterDescription
arrayRequired. Source to slice

Return Value

Return ValueDescription
*New array without the last element

Lodash Examples

Example 1 — Official: Drop the Last

Keep every element except the final one.

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

How It Works

  1. Source. Official sample: [1, 2, 3].
  2. Last item. 3 at index 2 is excluded.
  3. Keep. Indexes 0 and 1 → [1, 2].
  4. New array. The original list is unchanged.

Example 2 — Longer List

Same rule on four letters: drop only the last.

Lodash
_.initial(["a", "b", "c", "d"]);
// → ["a", "b", "c"]
Try It Yourself

How It Works

  1. Four items. Indexes 0 … 3.
  2. Drop. "d" is the last → removed from the result.
  3. Keep. a, b, c remain in order.
  4. Length. Result length is 3 (4 − 1).

Example 3 — Single Element

The only element is also the last — so the result is empty.

Lodash
_.initial([42]);
// → []
Try It Yourself

How It Works

  1. One slot. Index 0 holds 42.
  2. It is the last. Dropping the last removes that only item.
  3. Result. Empty array [].
  4. Safe. No throw — useful when length may be 0 or 1.

Example 4 — Empty Array

Nothing to keep — still returns a new empty array.

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

How It Works

  1. Empty source. Length is 0.
  2. No last item. There is nothing to drop or keep.
  3. Result. [].
  4. Idempotent feel. Safe default in pipelines that always call initial.

Example 5 — _.initial vs _.tail

Opposite ends: drop last vs drop first.

Lodash
var nums = [1, 2, 3];

_.initial(nums);  // → [1, 2]
_.tail(nums);     // → [2, 3]
_.last(nums);     // → 3
Try It Yourself

How It Works

  1. Initial. Drops 3 → [1, 2].
  2. Tail. _.tail drops 1 → [2, 3].
  3. Last. _.last keeps only the dropped tail value → 3.
  4. Pair. initial + last split a list into “prefix” and “final item”.

Browser & Runtime Support

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

✓ Stable · Lodash 4.x

_.initial()

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

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import initial from "lodash/initial" for smaller builds. Native alternative: arr.slice(0, -1).

Frequently Asked Questions

_.initial(array) returns a new array with every element except the last. The original array is not changed.
Both return []. An empty array has nothing to keep; a one-element array’s only item is the last, so dropping it leaves nothing.
No. It returns a new slice. The source array is unchanged.
_.tail drops the first element. _.initial drops the last element. They are opposites.
For ordinary arrays the result matches arr.slice(0, -1) and _.dropRight(arr, 1). Lodash keeps the same import style as other helpers.
Use import initial from "lodash/initial" or require("lodash/initial") for tree-shaking friendly bundles. Full build: import _ from "lodash" then _.initial.

Next: _.intersection()

Create an array of unique values present in all given arrays.

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