How to log unicode characters to the console in JavaScript?

后端 未结 3 1836
旧时难觅i
旧时难觅i 2021-01-17 17:21

I have a hungarian statement that I would like to log to the console like this:

console.log(\'Probléma a működésben.\');

But it prints the

相关标签:
3条回答
  • 2021-01-17 17:58

    First way: you have to find your characters in unicode table

    console.log( '\u03A9' ); // Ω

    Second way - use unidecode npm package.

    0 讨论(0)
  • 2021-01-17 18:16

    You can specify the encoding of your file by setting the charset attribute

    <script src="script.js" type="text/javascript" charset="utf-8"/>
    
    0 讨论(0)
  • 2021-01-17 18:21

    I found out that if you set the proper charset in a <meta> tag in the <head> it will work:

    <meta charset="UTF-8">
    
    0 讨论(0)
提交回复
热议问题