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

137
Vistas
How do I access new Map() keys and values with .get()

I have Function that maps out an Array in to Groups and now I want to access the keys and values in the groups

toDoList Array

Code to group array with new Map()

reduceArray() {
  console.log("this.toDoList", this.toDoList);
  const MapArrayIntoGroups = this.toDoList.reduce(
    (Map, e) => Map.set(e.ID, [...Map.get(e.ID)||[], e]),
    new Map()
  );
  console.log("MapArrayIntoGroups",MapArrayIntoGroups);
  const key = MapArrayIntoGroups.get(); // get Key
  console.log("key",key);
  const value = MapArrayIntoGroups.get(); // value array
  console.log("value",value);
}

Here is the result

result of mapping

I have trying MapArrayIntoGroups.get(value); etc.. with no success. How do I access those keys, values

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can iterate your map with for of:

for (const [key, value] of MapArrayIntoGroups) {
  console.log(key)
  console.log(value)
}

or forEach:

MapArrayIntoGroups.forEach(function(value, key) {
  console.log(key)
  console.log(value)
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

Instead of

const key = MapArrayIntoGroups.get(); // get Key
console.log("key",key);
const value = MapArrayIntoGroups.get(); // value array
console.log("value",value);

Do like that to get the value if you know the key

const key = 1496
const value =MapArrayIntoGroups.get(key);

How do I access those keys, values

//utility function to get keys of each entry
const keys = arrays => arrays.map(array=>array[0]);

// keys([...MapArrayIntoGroups]);// try this to get all keys like an array [1496,...]

Thanks @Heretic said in comments that map has Already a method called keys(); Which is self-explanatory get all keys of an map

Array.from(MapArrayIntoGroups.keys());
//or
[...MapArrayIntoGroups.keys()];
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