Saturday, November 16, 2024
Google search engine
HomeLanguagesJavascriptUnderscore.js _.unescape() function

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:




<!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>


Output:

Example 2:




<!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>


Output:

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

Most Popular

Recent Comments