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

208
Views
How to combine two arrays into one object so that the values of the first array are keys, and the values of the second array are values

Two objects are given const en = ["mon",  "tue",  "wed",  "thu",  "fri",  "sat",  "sun"]; const de = ["montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"];

It is necessary to combine these 2 arrays into one object so that the values of the first array are keys, and the values of the second array are values. How to do it?

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

0

You can do it using Object.fromEntries.

const 
  en = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"],
  de = ["montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"],
  result = Object.fromEntries(en.map((k, i) => [k, de[i]]));

console.log(result);

You can also reduce one of the arrays into the desired object.

const 
  en = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"],
  de = ["montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"],
  result = en.reduce((acc, k, i) => ({ ...acc, [k]: de[i] }), {});

console.log(result);

about 4 years ago · Juan Pablo Isaza Report

0

Another solution using map, easy to understand:

const en = ["mon",  "tue",  "wed",  "thu",  "fri",  "sat",  "sun"];
const de = ["montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"];
let result = {};

en.map((item, index) => result[item] = de[index])
about 4 years ago · Juan Pablo Isaza Report

0

Iterate over over the first array and collect the elements of the second at th e matching index:

   const en = ["mon",  "tue",  "wed",  "thu",  "fri",  "sat",  "sun"];
   const de = ["montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"];
   let dict={}
 ;

   en.forEach ( (px, pn) => { dict[px] = de[pn]; });

   console.log(dict);

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!