I have an array of objects and I am using the map function to reduce that array of objects to be an array of a single element in each object. After that I am removing the dup elements in that array. After doing that I have a array like arr = ["100", "101", "103", "104", "105"] but I want to have a key name for each element like arr =[{id: 100},{id: 101}, {id: 103},{id: 104},{id: 105}].
My initial array of objects:
const options = [
{ id: 1, value: 'chocolate', label: 'Chocolate' },
{ id: 2,value: 'strawberry', label: 'Strawberry' },
{ id: 3,value: 'vanilla', label: 'Vanilla' },
{ id: 4,value: 'vanilla', label: 'Vanilla' },
];
let testArr = options.map(a => a.value);
let uniqueTest = [...new Set(test)];
So uniqueTest gives an array like ["chocolate", "strawberry", "vanilla"]
What I want is an array with key names if that is possible.
Array.prototype.map! You can thenmapeach key to an object{ id: key }.