4
I’m having an unexpected behavior with the unique
jQuery.
The following command:
var x = [1,2,1,2];
var y = $.unique(x);
document.write(y);
Chrome results in 1,2
(which is correct), but in Firefox appears 1,2,1,2
.
Is this a bug, or was it meant to be that way?
Here is an example from jsfiddle, open first in Chrome (works correctly) and then in Firefox (doesn’t work).
OBS: jQuery 2.1.0; Firefox 24.5.0; Google Chrome 34.0.1847.131 m.
I found on jQuery bugs page the following:
$.unique() is only designed to work on DOM nodes, not on arrays of strings.
http://bugs.jquery.com/ticket/7036– Sergio
@Sergio, the bug is closed as invalid > "closed bug: invalid"
– guisantogui
@guisantogui The bug is invalid precisely because the function is being used differently than it was designed.
– dang
Hint: To get unique elements from an Array, convert it to an object. Every Javascript object is practically a dictionary, so you can guarantee the uniqueness ;) Example with all values like
true
:var z = {"1": true, "2": true};
– Oralista de Sistemas