Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple JavaScript shortcut

Eliminating all duplicates in array with reduce() reduce take 4 params previousValue, currentValue, index, array

array.reduce((acc, el, i, arr) => {
    if (arr.indexOf(el) !== i && acc.indexOf(el) < 0) acc.push(el); return acc;
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment