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
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With