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!
LVL 1
tjyoungAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hankknightCommented:
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.
0
hankknightCommented:
You could use contains() like this:
if (!$('#newmodel option:contains("'+ String(data.models[i].name +" " + data.models[i].years[j].styles[k].name).replace(/ \([^)]*\)/, '') +'")').html()) $("#newmodel").append(option);

Open in new window

Here is an example:
http://jsfiddle.net/n84bf/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tjyoungAuthor Commented:
Thats fabulous. Never would have figured that out. Many thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.