const removeDouplicate = (arr) => Object.keys( arr.reduce((res, val) => ({ ...res, [val]: true }, {}) );
Regarding comments about returning a string array independent of the input data:
const removeDouplicate = (arr) => Object.entries( arr.reduce((res, val) => ({ ...res, [val]: val }, {}) ).map(([_, val]) => val);
Regarding comments about creating N number of objects:
const removeDouplicate = (arr) => Object.entries( arr.reduce((res, val) => ( res[val] = val, res ), {}) ).map(([_, val]) => val);
This will work for all arrays as long as they only contain primitive values. Seeing as res[{ foo: 42 }] will access the index res['[object Object]'] no matter the object.
res[{ foo: 42 }]
res['[object Object]']
Yeah, fthis works but you are "mutating" the data itself
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Regarding comments about returning a string array independent of the input data:
Regarding comments about creating N number of objects:
This will work for all arrays as long as they only contain primitive values. Seeing as
res[{ foo: 42 }]
will access the indexres['[object Object]']
no matter the object.Yeah, fthis works but you are "mutating" the data itself