So I came across this odd interaction between Javascript Date objects being converted into Strings and the in
operator in IE11. The String that .toLocaleString()
returns for a date, doesn't work when checking for keys using the in
operator, even through another string with the exact same text works just fine.
The interaction works correctly in Chrome, but seems to fail in IE11. What am I missing here and is there a way to get around this?
let days = {
Monday: {},
Tuesday: {},
Wednesday: {},
Thursday: {},
Friday: {},
Saturday: {},
Sunday: {}
};
// The example date should be a Monday
let currentDate = new Date('2018/8/20');
let currentDay = currentDate.toLocaleString('en-us', {
weekday: 'long'
});
console.log(currentDay);
console.log(typeof currentDay);
console.log(currentDay in days);
console.log('Monday' in days);
Thanks for any input!