DEV Community

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

mitya profile image

From some object with array inside. Like this (array with fruits):

const elements = [
type: 'Product',
email: '',
isTasty: true,
fruits: ['kiwi', 'mango', 'banana', 'kiwi', 'banana', 'orange', ],

Thread Thread
blessinghirwa profile image
Blessing Hirwa Author • Edited on

Try this: => {
let unique_values = [ Set(element.fruits )]
// console.log(element.fruits)
return unique_values;

or simply do it like this:

console.log( =>
unique_values = [ 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