Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!