Bug Tracker

Opened 7 years ago

Closed 7 years ago

#11541 closed bug (invalid)

.unique() method, Can not remove duplicates in Google Chrome

Reported by: deg84 Owned by:
Priority: low Milestone: None
Component: misc Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:

Description

Confirm the phenomenon in Gogole Chrome 18.0.1025.142 beta

Example 1:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
var a = [1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2];
$.unique(a);
console.log(a);
</script>
</body>
</html>

Result:

[1,2,1]

But I hope Result:

[1,2]

or

[2,1]

Example2:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
var a = ['2012-02-01','2012-02-01','2012-02-01','2012-02-01','2012-02-01','2012-02-01','2012-02-01','2012-02-01','2012-02-01','2012-02-01','2012-02-01','2012-02-01','2012-02-02','2012-02-02','2012-02-02','2012-02-02','2012-02-02','2012-02-02','2012-02-02','2012-02-02','2012-02-02',];
$.unique(a);
console.log(a);
</script>
</body>
</html>

Result:

["2012-02-01", "2012-02-02", "2012-02-01"]

But I hope Result:

["2012-02-01", "2012-02-01"]

or

["2012-02-02", "2012-02-01"]

Change History (1)

comment:1 Changed 7 years ago by sindresorhus

Component: unfiledmisc
Priority: undecidedlow
Resolution: invalid
Status: newclosed

From the docs:

The $.unique() function searches through an array of objects, sorting the array, and removing any duplicate nodes. This function only works on plain JavaScript arrays of DOM elements, and is chiefly used internally by jQuery.

The method only accepts an array of DOM elements, not strings or numbers.

Note: See TracTickets for help on using tickets.