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

146
Vistas
Can I use the same map key several times?

I'm storing and retrieving data like this:

data = new Map();
data.set("key", id);
data.set("key", id2);
data.get("key");

the second set is overwriting key element. I want a structure, that can hold multiple times the key element or one key element with multiple id data pairs. Does such a collection exist in Javascript or how to achieve this?

thank you

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

0

JS Map and no other JS structure I'm aware of allows you to have more occurences of the same key. Keys must be unique.

I think that maybe unshifting new values into an array stored in a regular object might be a good way to achieve what you want. That way, your newest value will always be the first in the array, and thus accessible at index 0, like so:

const data = {key: []};

data.key.unshift(id);
data.key[0] // value of id

data.key.unshift(id2);
data.key[0] // value of id2
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