DEV Community

[Comment from a deleted post]
Collapse
 
eatsjobs profile image
Pasquale Mangialavori

what about this one?we can iterate just one time

function removeDuplicated(arr, key = 'id') {
    const map = new Map();
    arr.map(el => {
        if (!map.has(el[key])) {
            map.set(el[key], el);
        }
    });
    return [...map.values()];
}