I just recently discovered the "Set" data type in ES6. Love it so far. I am working on a Autoselect which consists of multiple options, but I don't want to show duplicates. Thats why I use the Set-Datatype.
For example:
I have this array of uploads:
const uploads = [
{projectNr: PUE-200, projectDesc: "This is project 200"},
{projectNr: PUE-200, projectDesc: "This is project 200"},
{projectNr: PUE-201, projectDesc: "This is project 201"},
{projectNr: PUE-201, projectDesc: "This is project 201"},
{projectNr: PUE-202, projectDesc: "This is project 202"}
]
I need an array for my Autoselector consisting of an instance of every project but no duplicates. I managed to retrieve the project numbers like this (PUE-200, PUE-201, PUE-202 and so on) but I also need the description. My approach was to split the project into to Sets. One for the project number and the other one for the description. Both Sets are complete but now I need them in an array. I tried to use the spread operator, it kinda works but I need both values as an actual value of an array element in order to map it.
My current situation:
["PUE-200", "This is project 200", "PUE-201", "This is project 201"]
What I need:
[
{ProjektNr:"PUE-200", ProjektDesc: "This is project 200",
{ProjektNr:"PUE-201", ProjektDesc: "This is project 201""}
]
Edit: This is my current code:
const uniqueProjektNr = new Set();
const uniqueProjektBeschreibung = new Set();
uploads.map((upload) => {
uniqueProjektNr.add(upload.ProjektNr);
uniqueProjektBeschreibung.add(upload.ProjektBeschreibung);
});
let uniqueProjektHolder = [...uniqueProjektNr, ...uniqueProjektBeschreibung];