Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

225
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda