How to create an array of unique values using Set? ES6 introduces Set, which returns unique values This article will go through how to remove duplicates and create an array of unique values ES6 Set. What is ES6 Set? The Set object is a data type that can store unique values without any particular order. We can pass in a parameter, and all of its elements will be added to the new Set. const result = new Set (parameter); How to create an array with unique values? For example, we want to create a new array with unique category values. const food = [ { name : "egg" , category : "breakfast" , }, { name : "burger" , category : "lunch" , }, { name : "steak" , category : "dinner" , }, { name : "chicken" , category : "lunch" , }, { name : "eggs" , category : "breakfast" , }, { name : "spaghetti" , category : ...
Comments
Post a Comment