Lodash _.unescape() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
String

Definition

The inverse of _.escape. Converts the HTML entities &amp;, &lt;, &gt;, &quot;, and &#39; back to &, <, >, ", and '. Part of Lodash String (stable since 0.6.0 — not deprecated). Note: no other HTML entities are unescaped — use a library like he for fuller decoding.

Pass the string and options shown below. Check the return type before you chain another helper.

Syntax

Call _.unescape. Start with this line.

Lodash
_.unescape([string=''])
CallWhat it does
_.unescape([string=''])Primary signature.
_.unescape(string)Transform or inspect a string.

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

Library declarations
Lodash
_.unescape([string=''])

Parameters

ParameterDescription
stringOptional. Value to unescape (default '')

Return Value

Return ValueDescription
*New string with the five entities decoded

Lodash Examples

Example 1 — Official: Decode &amp;

Restore an ampersand from its HTML entity.

Lodash
console.log(
  _.unescape("fred, barney, &amp; pebbles")
);
// 'fred, barney, & pebbles'
Try It Yourself

How It Works

  1. Input. The string contains the entity &amp;.
  2. Decode. Lodash replaces it with &.
  3. Result. Readable text with a real ampersand.
  4. Docs. Matches the official example.

Example 2 — All Five Supported Entities

Decode every entity that Lodash handles.

Lodash
console.log(
  _.unescape("&amp; &lt; &gt; &quot; &#39;")
);
// '& < > " \''
Try It Yourself

How It Works

  1. Set. Five entities appear in one string.
  2. Map. Each becomes its character.
  3. Quotes. &quot; → ", &#39; → '.
  4. Limit. This is the full Lodash unescape set.

Example 3 — Escape Then Unescape

Round-trip with the inverse helper.

Lodash
var raw = "Tom & Jerry <3";
var escaped = _.escape(raw);
var back = _.unescape(escaped);

console.log(escaped);
// 'Tom &amp; Jerry &lt;3'
console.log(back);
// 'Tom & Jerry <3'
console.log(back === raw); // true
Try It Yourself

How It Works

  1. escape. Special characters become entities.
  2. unescape. Those entities become characters again.
  3. Equal. The round-trip matches the original.
  4. Pair. See _.escape.

Example 4 — Other Entities Stay

Only Lodash’s five entities are decoded.

Lodash
console.log(_.unescape("&nbsp; &copy; &amp;"));
// '&nbsp; &copy; &'
Try It Yourself

How It Works

  1. nbsp / copy. Left as literal entity text.
  2. amp. Decoded to &.
  3. Why. Lodash keeps the API small and paired with _.escape.
  4. Tip. Official docs suggest he for more entities.

Example 5 — Plain Text Unchanged

No entities means no changes.

Lodash
console.log(_.unescape("hello world"));
// 'hello world'
Try It Yourself

How It Works

  1. Scan. No supported entities are found.
  2. Return. The same text comes back.
  3. Safe. Fine to call on mixed known/unknown input.
  4. Default. Omitting the argument returns ''.

Browser & Runtime Support

_.unescape is a Lodash String helper available since 0.6.0. It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 4.x

_.unescape()

Available in [email protected] full builds and the lodash/unescape 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
_.unescape Since 0.6.0

Bottom line: Safe for production once Lodash is on the page. Prefer import unescape from "lodash/unescape" for smaller builds. For full HTML entity decoding, use a dedicated library such as he.

Frequently Asked Questions

_.unescape([string='']) converts the HTML entities &amp;, &lt;, &gt;, &quot;, and &#39; back to &, <, >, ", and '. Official: _.unescape('fred, barney, &amp; pebbles') → 'fred, barney, & pebbles'.
Yes. _.escape encodes those five characters; _.unescape decodes those five entities.
No. Only those five. Entities like &nbsp; or &copy; stay unchanged. Use a library such as he for fuller HTML entity decoding.
No. Strings are immutable. _.unescape always returns a new string.
Use _.escape when inserting untrusted text into HTML. Use _.unescape when you stored escaped text and need the original characters again.
Use import unescape from "lodash/unescape" or require("lodash/unescape"). Full build: import _ from "lodash" then _.unescape.

Next: _.upperCase()

Convert a string to uppercase words separated by spaces.

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