Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery $.unique() issue ie

Tags:

jquery

var arr = new Array(); arr[0] = 'Departmental News' arr[1] = 'Departmental News' arr[2] = 'Another Cat' arr[3] = 'Another Cat' arr[4] = 'Departmental News'

            alert(arr)

            alert($.unique(arr))

In IE I get duplicates. In any other browser only the unique ones

Any Ideas?

like image 251
vanzylv Avatar asked May 10 '26 05:05

vanzylv


1 Answers

This is the intended behavior. Though $.unique() does work for strings in most cases, it's not guaranteed to, the documentation specifically states it's only for DOM elements.

From the docs:

Sorts an array of DOM elements, in place, with the duplicates removed. Note that this only works on arrays of DOM elements, not strings or numbers.

The way it works internally works for DOM elements cross-browser, but that same implementation doesn't work consistently for other things, namely strings/numbers which is why they're singled out so specifically in the documentation.

like image 196
Nick Craver Avatar answered May 12 '26 23:05

Nick Craver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!