Data View to get Distinct list

Is it possible to use a Data View to get a distinct list? For instance, I have a server connect that returns records that all have a city. I currently have a seperate server connect which returns a Distinct list of cities. Is it possible to do that client side with a Data View?

Thanks.

1 Like

Would love to know if you ever got this question answered…
Is it possible to get distinct records returned using a dataview filter, if so what would the syntax be??

This thread might offer a method.

1 Like

Here’s a solution.

const array =
[
{ “name”: “London”, “pop”: 17000 },
{ “name”: “Cardiff”, “pop”: 17000 },
{ “name”: “Pontypridd”, “pop”: 35000 }
]

function uniqueByKey(array, key) {
return […new Map(array.map((x) => [x[key], x])).values()];
}

console.log(uniqueByKey(array, ‘pop’));

Try it online here:

https://onecompiler.com/javascript/3y6cmhvmz

1 Like