DEV Community

Discussion on: 8 neat Javascript tricks you didn't know in 4 minutes.

blessinghirwa profile image
Blessing Hirwa Author • Edited on

Try this:

elements.map((element) => {
let unique_values = [...new Set(element.fruits )]
// console.log(element.fruits)
return unique_values;
})

or simply do it like this:

console.log(elements.map((element) =>
unique_values = [...new Set(element.fruits )]
))

You can either console them or store them in a variable. Overwriting the old values is also possible.

Some comments have been hidden by the post's author - find out more