Last active
June 17, 2020 03:06
-
-
Save marcelo-ribeiro/04a103d02788827a385283af0e8cc36d to your computer and use it in GitHub Desktop.
Create Unique Array, Remove Array Duplicates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const products = [ | |
{id: 1, title: "Trim Dress", category: "women", collection: ["new", "featured"]}, | |
{id: 2, title: "Belted Dress", category: "women", collection: ["featured"]}, | |
{id: 3, title: "Fitted Dress", category: "men", collection: ["new"]} | |
]; | |
const categories = new Set( | |
products.map(product => product.category) | |
); | |
// Created using inner array | |
const collection = new Set( | |
...products.map(product => | |
product.collection.map(item => item) | |
) | |
); | |
console.log([...categories]); | |
// ["women", "men"] | |
console.log([...collection]); | |
// ["new", "featured"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numeros = [2,3,4,4,2,3,3,4,4,5,5,6,6,7,5,32,3,4,5]; | |
console.log([...new Set(numeros)]); | |
// [2, 3, 4, 5, 6, 7, 32] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment