Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

214
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda