Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do you insert a variable into a character escape in javascript

I’m attempting to update the icons used in an application that has a nested webview within it. I’m currently able to load specific icons with our icon font using specific hex codes like this: "\u{F053D}". The problem I’m running into is now that I’m trying to get dynamic icons defined from elsewhere in the application, I can’t find a valid syntax to instert a variable into the place of the static hex code I was testing with.

Here are a few things I tried with hexCode representing a variable containing a string value like "F053D":

'\u{hexCode}' '\u{${hexCode}}' '\u{' + hexCode + '}'

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But these say that a Hexadecimal didgit is expected after \u. Is there a way to insert a hex code here dynamically that I’m missing?

>Solution :

All you need to do is use String.fromCodePoint to convert the hex sequence into a unicode string:

let hexCode = '1F600'

console.log(`Hello ${String.fromCodePoint(parseInt(hexCode, 16))} World`)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading