How to decode HTML code in Unicode format?

How to use JavaScript to decode:

\u003cb\u003estring\u003c/b\u003e 

to

 <b>string</b> 

(I searched on the Internet, there is a site with the same question as: Javascript html decoding
or How to decode HTML objects
but it does not have the same fomat code )
Thank you very much!

+6
source share
2 answers
 decodeURIComponent('\u003cb\u003estring\u003c/b\u003e'); // "<b>string</b>" 

Edit - I would delete the answer above if I could.

The original question is a bit ambiguous.

console.log('\u003cb\u003estring\u003c/b\u003e'); will already give <b>string</b>

If the characters \ escaped, then instead of replacing \\ you can replace the replacement method \\ only \ , which allows you to use the correct Unicode sequence.

+7
source

This is a duplicate. How to decode a shielded unicode string? . One of the answers received should work:

 var x = '\\u003cb\\u003estring\\u003c/b\\u003e'; JSON.parse('"' + x + '"') 

Output:

 '<b>string</b>' 
+14
source

All Articles