JQuery $.unique() issue ie
var arr = new Array(); arr[0] = 'Departmental News' arr[1] = 'Departmental News' arr[2] = 'An开发者_开发知识库other 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?
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.
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/
精彩评论