August 05, 2019
// The solution is to map your objects to the array of identifiers. note: This only works if the identifier is, or can be reduced to, a primative type. If you supply objects it will use object references which might not act as you expect. There is no IEquatable in JS either. // map objects to a list of identifier strings let areaNames = stagingBuild.workitems.map(x => x.area) //distinct categories will be distinct! The set will check if the value already exists // A value in the Set may only occur once; it is unique in the Set's collection. const distinctCategories = [...new Set(areaNames)] // watch out becuase undefined and NaN can be stored in the Set. // And in the case of strings, casing is respected for uniqueness
Hi! I'm Darragh ORiordan. I live and work in Auckland, New Zealand 🥝 enjoying the ocean 🏄 and building things on the web 💻 Contact me on Twitter!