• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

310
Views
Javascript - how to take array of abbreviated days and output full name of days

I am trying to take a report of class meeting days in abbreviated form. Each row has an array of days (M,T,W,TH,F,S,SU). How could I loop through the array and change each value of:

M to Monday T to Tuesday W to Wednesday TH to Thursday F to Friday S to Saturday SU to Sunday

I would like to keep the array intact. To switch from {M,W,F} to {Monday,Wednesday,Friday}.

I have tried to for loop through and use a switch in the loop with no luck.

Can you help?

about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I would use a constant map to help me translate from short to long.

Like this:

const DAYS_SHORT_TO_LONG = {
  SU: 'Sunday',
  M: 'Monday',
  T: 'Tuesday',
  W: 'Wednesday',
  TH: 'Thursday',
  F: 'Friday',
  S: 'Saturday',
}

const daysToConvert = ['M', 'SU', 'F', 'TH'];

const result = daysToConvert.map((shortDay) => DAYS_SHORT_TO_LONG[shortDay]);

console.log(result);

about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error