I have a list of lists containing IDs in javascript, I want them to be added to a set which maintains insertion order and has only unique values
            Asked
            
        
        
            Active
            
        
            Viewed 2,337 times
        
    7
            
            
        1 Answers
12
            
            
        This is exactly what JavaScript's Set does. It contains only unique values, and iterates in insertion order. Example:
const s = new Set();
s.add("q");
s.add("x");
s.add("c");
s.add("q"); // duplicate
for (const v of s) {
  console.log(v); // q, x, c -- insertion order
} 
    
    
        T.J. Crowder
        
- 1,031,962
- 187
- 1,923
- 1,875
 
    