Is there a correct way to go about grabbing the name of a day, when you have the short version, such as the following:
mon
tue
wed
thu
fri
sat
sun
I don't need an actualy "date" or time or anything, I just need the string for the full date name.
Is there a correct way to go about grabbing the name of a day, when you have the short version, such as the following:
mon
tue
wed
thu
fri
sat
sun
I don't need an actualy "date" or time or anything, I just need the string for the full date name.
A simple associative array (read object) dictionary would suffice:
var days = {
'mon': 'Monday',
'tue': 'Tuesday',
'wed': 'Wednesday',
'thu': 'Thursday',
'fri': 'Friday',
'sat': 'Saturday',
'sun': 'Sunday'
}
Now, you can access them as follows:
var day = 'mon',
full = days[day]; // full === 'Monday';
small enhancement to @BenM answer
var Days = {
'mon': 'Monday',
'tue': 'Tuesday',
'wed': 'Wednesday',
'thu': 'Thursday',
'fri': 'Friday',
'sat': 'Saturday',
'sun': 'Sunday',
getFullName: function(day) {
return this[day];
}
}
Days.getFullName("mon");
@BenM already added an answer. Just extending his answer,
var days = {
'mon': 'Monday',
'tue': 'Tuesday',
'wed': 'Wednesday',
'thu': 'Thursday',
'fri': 'Friday',
'sat': 'Saturday',
'sun': 'Sunday'
}
var shortDays = ['mon','tue','wed','thu','fri','sat','sun'];
var getFulldays = shortDays.map(function(day){
return days[day]
})
console.log(getFulldays)
In JS as of ES6, actually the Map object is the proper way of doing this job since it is more efficient than object access. A very simplistic implementation is as follows;
var days = new Map([["mon", 'Monday'],
["tue", "Tuesday"],
["wed", "Wednesday"],
["thu", "Thursday"],
["fri", "Friiday"],
["sat", "Saturday"],
["sun", "Sunday"]
]);
console.log(days.get("thu"));