Invisible character with IE when using Intl.DateTimeFormat

As explained in some threads, Internet Explorer adds some invisible extra characters when returning a date from the JavaScript function new Intl.DateTimeformat.

var day = "Thursday";
var intlDay = new Intl.DateTimeFormat('en-US', {weekday:"long"}).format(new Date(2019,1,7));
console.log(day === intlDay); // return FALSE with IE
intlDay = intlDay.replace(/\u200E/g, ''); // replace \u200E
console.log(day === intlDay); // return TRUE with IE

The trick is to replace \u200E in the returned string.

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

*