Underscore.js _.unescape() function

Underscore.js is a library in javascript that makes operations on arrays, string, objects much easier and handy. _.unescape() function is used to unescape a special character. It works opposite of _.escape() function. It do convert “&” to “&” and so on. 

Syntax:

_.unescape(string);

Parameters: It takes only one parameter i.e the string.

Returns: String is returned by this function.

Note: Some specials files are needed to be included while using this code directly in the browser. It is very necessary to link the underscore CDN before going and using underscore functions in the browser. When linking the underscore.js CDN The “_” is attached to the browser as a global variable.



Some examples are given below for a better understanding of this function.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
  <head
    <script src =  
    </script
   </head
  <body>
    <script>
      let str="<HTML><HEAD></HEAD></HTML>";
      let str2=_.unescape(str)
      console.log(`Original string is: ${str}`)
      console.log(`New string is: ${str2}`)
    </script>
  </body
</html>

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html> 
  <head> 
    <script src =  
    </script> 
   </head> 
  <body>
    <script>
      console.log(`& is represented as: ${_.unescape("&")}`)
      console.log(`&#x27; is represented as: ${_.unescape("'")}`)
      console.log(`> is represented as: ${_.unescape(">")}`)
      console.log(`< is represented as: ${_.unescape("<")}`)
    </script>
  </body> 
</html>

chevron_right


Output:

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.