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

222
Vistas
How to delete the first inserted item in a Map?

I want to have something like Java's linkedHashMap, where the elements in it are in insertion order, and I can extract the first inserted and/or also remove it from the map, as I need. I know that in js, by default, maps store by insertion order but I can't figure out how to both extract the value & key of the first inserted, and then remove that item(the pair) from the map. Sort of like removing the first from a queue. Given that js Maps are defaulted to be stored in insertion order, I figure this should be possible, but I don't know how to do it.

for context, I'm doing this to improve the efficiency of a leetcode question, that uses the sliding window pattern.

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

0

Well if all you want is to remove the first inserted key-value pair from a Map, then you could simply do:

map.delete(map.keys().next().value)

Depending on the requirements of the full problem you are trying to solve of course, you could optimize this by storing the keys iterator in a variable or something of the like.

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