Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log unicode characters to the console in JavaScript?

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 following:

> Probléma a működésben.

The non ASCII characters are messed up, but I don't think the reason for this is that the console doesn't support Unicode characters, because if I paste the log straight into the console it produces the proper output.

I tested it in Opera, Firefox, Chrome. Happens in Win 8.1 and OSX too, so we can say this is general.

Are there other things that should persist for the proper Unicode console logging, like HTML charset or file encode?

like image 348
totymedli Avatar asked Jul 02 '15 21:07

totymedli


1 Answers

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

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

Second way - use unidecode npm package.

like image 152
Kas Elvirov Avatar answered Oct 06 '22 00:10

Kas Elvirov