re: How to remove duplicate objects from an array (javascript) VIEW POST

FULL DISCUSSION
 

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()];
}
code of conduct - report abuse