Skip to content
Related Articles

Related Articles

Improve Article

Lodash _.escape() Method

  • Last Updated : 07 Sep, 2020

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.

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

Syntax:

_.escape([string=''])

Parameters: This method accepts single parameter as mentioned above and described below:

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

Return Value: This method returns the escaped string.



Example 1:

Javascript




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

Output:

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

Example 2:

Javascript




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

Output:

"Geeks &amp; Geeks"
"GFG &#30;+' Geeks"
"'Geeks'"
My Personal Notes arrow_drop_up
Recommended Articles
Page :