Monday, February 23, 2026
HomeLanguagesJavascriptLodash _.escape() Method

Lodash _.escape() Method

Lodash _.escape() method is used to convert the characters “&”, “<“, “>”, ‘”‘, and “‘” of the given string into their corresponding HTML entities.

Syntax:

_.escape([string='']);

Parameter:

  • string: This parameter holds the string containing escape characters.

Return Value:

This method returns the escaped string.

Example 1: In this example, we are converting ‘<‘, ‘<‘, and ‘&’ by using the _.escape() method.

Javascript




const _ = require('lodash');
 
let str1 = _.escape("Geeks << for >> Geeks");
console.log(str1);
 
let str2 = _.escape("GFG && Geeks");
console.log(str2);


Output:

"Geeks &lt;&lt; for &gt;&gt; Geeks"
"GFG &amp;&amp; Geeks"

Example 2: In this example, we are converting ‘&’, ‘+’, and ”(quote) by using the _.escape() method.

Javascript




const _ = require('lodash');
 
let str1 = _.escape("Geeks & Geeks");
console.log(str1);
 
let str2 = _.escape("GFG '+' Geeks");
console.log(str2);
 
let str3 = _.escape("'Geeks'");
console.log(str3);


Output:

Geeks &amp; Geeks
GFG '+' Geeks
'Geeks'
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32506 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6882 POSTS0 COMMENTS
Nicole Veronica
12005 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12099 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6967 POSTS0 COMMENTS
Umr Jansen
6956 POSTS0 COMMENTS