7

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

0

1 Answer 1

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
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.