Dev HelpersOpen library
← Back

Find the first unique value

Find the first unique value. A self-contained example using the JavaScript runtime.

Open this example in the interactive library

Source code

const xs = ["a", "b", "a", "c"];
const counts = new Map();
for (const x of xs) counts.set(x, (counts.get(x) || 0) + 1);
console.log(xs.find((x) => counts.get(x) === 1));

Sample output

b