Eliminate duplicate objects in a JavaScript array

Let's see an example on how to remove duplicate objects inside a JavaScript array:

jsx
let siblings = [
    {'name': 'Erik',   'age': 29},
    {'name': 'Andrea', 'age': 26},
    {'name': 'Paula',  'age': 15},
    {'name': 'Paula',  'age': 15},
    {'name': 'Lucas',  'age': 29},
    {'name': 'Erik',   'age': 27}          
]

We'll add friends to a unique group and filter duplicate values:

jsx
// Transforms objects into strings and creates a set (unique elements by definition)
let unique = [...new Set([...siblings].map(JSON.stringify))].map(JSON.parse)

Final result:

jsx
console.log(unique)
/*  {'name': 'Erik',   'age': 29},
    {'name': 'Andrea', 'age': 26},
    {'name': 'Paula',  'age': 15},
    {'name': 'Lucas',  'age': 29},
    {'name': 'Erik',   'age': 27} 
 */

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.