DEV Community

bomoniyi
bomoniyi

Posted on

Using .set to get get unique values in an array

const customerDishes = [
  "Chicken Wings",
  "Fish Sandwich",
  "Beef Stroganoff",
  "Grilled Cheese",
  "Blue Cheese Salad",
  "Chicken Wings",
  "Reuben Sandwich",
  "Grilled Cheese",
  "Fish Sandwich",
  "Chicken Pot Pie",
  "Fish Sandwich",
  "Beef Stroganoff"
];

const uniqueDishes = [...new Set(customerDishes)];
console.log(uniqueDishes)

// const numbers = new Set([[1], [2], [3]]);

// for (const num of numbers) {
//   console.log(num);  
// }
Enter fullscreen mode Exit fullscreen mode

When you put the values in the .set array in [] to form an object, the .set method can't recognize this as unique anymore (as in above comment)

Top comments (0)