Link to home
Start Free TrialLog in
Avatar of tjyoung
tjyoung

asked on

Possible to remove duplicates from a selectlist populated by json?

Hi,
I have a selectlist that is populated by json. The issue I'm having is I get duplicates in my selectlist and I'm hoping I can remove them as the selectlist loads.

I have a fiddle to show you what I mean:
See Fiddle

The actual vehicles aren't really 'duplicates' but since I'm only showing a select amount of the supplied data (name and basic style) they appear duplicate in the select.

I came across juery.unique() but not sure if that would work... or how to apply it in this instance. Any help would be appreciated.

Thanks!
Avatar of hankknight
hankknight
Flag of Canada image

There are not actually any duplicates in your example.  

For example:
<option value="200420764">ATS Luxury 4dr Sedan</option>
<option value="200420763">ATS Luxury 4dr Sedan</option>
<option value="200420762">ATS Luxury 4dr Sedan</option>

While the text is the same, the value is different.

Notice this in your JSON:

                "id": 200420764,
                "name": "Luxury 4dr Sedan (3.6L 6cyl 6A)",
and

                "id": 200421837,
                "name": "Luxury 4dr Sedan (3.6L 6cyl 6A)",
Because the ID is the key and it is unique, using something like juery.unique() would not help.
ASKER CERTIFIED SOLUTION
Avatar of hankknight
hankknight
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tjyoung
tjyoung

ASKER

Thats fabulous. Never would have figured that out. Many thanks!