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

74
Views
Matches 2 date arrays up

I wonder if anyone could help me.

I have an array of dates, which looks like

dates_array_a = ["2021-12-07","2021-12-08","2021-12-09","2021-12-10","2021-12-11","2021-12-12","2021-12-13","2021-12-14"];

I then have another set of array dates, but this time they have a numeric value

dates_array_b = [ ['2021-12-07', 100], ['2021-12-10', 555], ['2021-12-13', 750] ];

How can I do a for loop on "dates_array_a" and then look for any matches in "dates_array_b", so it creates the following;

2021-12-07 100
2021-12-08 100
2021-12-09 100
2021-12-10 555
2021-12-11 555
2021-12-12 555
2021-12-13 750
2021-12-14 750

I basically want to run a for loop, then create a fresh array from the results using push

I would post my inital code, but I have no idea where to start

Any help or advice would be really appriciated

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

0

May be this code can help you:

dates_array_a = ["2021-12-07","2021-12-08","2021-12-09","2021-12-10","2021-12-11","2021-12-12","2021-12-13","2021-12-14"];
dates_array_b = [ ['2021-12-07', 100], ['2021-12-10', 555], ['2021-12-13', 750] ];

let lastKnownKey;
const result = dates_array_a.map((dateA) => {
  const [date, key] = dates_array_b.find(([dateB]) => dateB === dateA) ?? [null, null]
  lastKnownKey = key ?? lastKnownKey;
  return `${dateA} ${lastKnownKey}`;
});

console.log(result);
.as-console-wrapper{min-height: 100%!important; top: 0}

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!