tags:

views:

141

answers:

2

Hi Guys

            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?

+2  A: 

This function is not meant to be used to filter duplicate strings. See the jQuery docs:

Note that this only works on arrays of DOM elements, not strings or numbers.

http://api.jquery.com/jQuery.unique/

awgy
thanks,I should read the docs
vanzylv
+4  A: 

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.

Nick Craver
thanks,I should read the docs
vanzylv