Assuming I have the following:
var array =
[
{\"name\":\"Joe\", \"age\":17},
{\"name\":\"Bob\", \"age\":17},
{\"name\":\"Carl\
I wrote my own in TypeScript, for a generic case, like that in Kotlin's Array.distinctBy {}
...
function distinctBy(array: T[], mapFn: (el: T) => U) {
const uniqueKeys = new Set(array.map(mapFn));
return array.filter((el) => uniqueKeys.has(mapFn(el)));
}
Where U
is hashable, of course. For Objects, you might need https://www.npmjs.com/package/es6-json-stable-stringify