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

147
Visualizações
How might I go about storing a massive number of unique entries in Javascript?

I am attempting a a project which requires me to record each unique URL visited by the user, with the goal being to have a way of storing each array to keep them unique.

Is there an efficient way to do this? Obviously this could be theoretically massive, possibly tens of thousands of entries if it was an array which would not do - how might I go about storing them?

(I do realise this is vague but even if your answer is just no that is not probable or smart that would be useful :) )

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

...possibly tens of thousands of entries if it was an array which would not do...

Arrays can contain tens of thousands, or even hundreds of thousands, of elements.

But for uniqueness, you want a Set rather than an array, as it offers sub-linear lookup time compared to linear lookup time on an array, and better semantics for sets of unique values..

Here's an example building a set of a million unique otherwise-random numbers:

const set = new Set();
console.time("Time to build the set");
while (set.size < 1_000_000) {
    set.add(Math.random()); // Won't add duplicate elements
}
console.timeEnd("Time to build the set");
console.log(`The set contains ${set.size.toLocaleString()} unique otherwise-random numbers`);

For me, that runs in about 200ms. Whereas I gave up on the equivalent using an array after several minutes.

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