Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
Data massaging an array of Objects in JavaScript

I have the below array.

Const array = [
  {
    "day": "Monday",
    "beginHour": "08:30:00",
    "endHour": "17:00:00"
  },
  {
    "day": "Tuesday",
    "beginHour": "08:30:00",
    "endHour": "17:00:00"
  },
  {
    "day": "Wednesday",
    "beginHour": "08:30:00",
    "endHour": "17:00:00"
  },
  {
    "day": "Thursday",
    "beginHour": "08:30:00",
    "endHour": "17:00:00"
  },
  {
    "day": "Friday",
    "beginHour": "08:30:00",
    "endHour": "17:00:00"
  }
]

I am writing a function in NodeJs to handle this kind of array where the office hours and days might change based on the office. I am trying to return below value.

response = "Mon-Fri 8.30-5pm Closed Sat & Sun"

I have tried frying my brain up but I couldn't even get close.

Please advise/suggest. Extremely grateful.

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

0

Got a solution.... Try it out:

const array = [
  {
    "day": "Monday",
    "beginHour": "08:30:00",
    "endHour": "17:00:00"
  },
  {
    "day": "Tuesday",
    "beginHour": "08:30:00",
    "endHour": "17:00:00"
  },
  {
    "day": "Wednesday",
    "beginHour": "08:30:00",
    "endHour": "17:00:00"
  },
  {
    "day": "Thursday",
    "beginHour": "08:30:00",
    "endHour": "17:00:00"
  },
  {
    "day": "Friday",
    "beginHour": "08:30:00",
    "endHour": "17:00:00"
  }
];

//create a function 
const days = arr => {
  //get days and time
  const [mon,fri] = [arr[0],arr[arr.length-1]];
  //destructure
  const [dayM,openM,closeM] = Object.values(mon);
  const [dayF,openF,closeF] = Object.values(fri);
  
  return `${dayM}-${dayF} ${openM}-${closeF} Closed Sat & Sun.`;
};

console.log(days(array));

about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!