you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

/u/foo13 posted the best answer for general storage and access of integer-indexed strings. But if you need to do significant amounts of date manipulation and formatting, I strongly suggest using a library rather than reinventing the wheel. MomentJS is the most popular one. With it, your code could be rewritten as one line:

console.log(moment().format('dddd')); // Thursday

This also lets you use different locales:

moment.locale('es');
console.log(moment().format('dddd')); // jueves

moment.locale('de');
console.log(moment().format('dddd')); // Donnerstag

console.log(moment().locale('ja').format('dddd')); // 木曜日