Home > Web Front-end > JS Tutorial > Use jQuery to deduplicate and sort arrays

Use jQuery to deduplicate and sort arrays

php中世界最好的语言
Release: 2017-12-30 16:34:39
Original
3305 people have browsed it

What I bring to you this time is to use jQuery to deduplicate and sort arrays. We know that jQuery can operate arrays. This article will give you Let’s analyze it carefully.

The first is to remove duplicates.

<!DOCTYPE html>
 <html lang="en"> 
<head>
 <meta charset="UTF-8">
 <title>JQ去重</title> 
</head> 
<body> 
<script src="jquery-1.7.2.min.js"></script>
 <script>
 var yearArray = new Array(2009, 2009, 2010, 2010, 2009, 2010); 
$.unique(yearArray);
 console.log(yearArray);//2009,2010 
</script>
 </body> 
</html>
Copy after login

Sort first and then remove duplicates

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta charset="UTF-8"> 
<title>JQ去重+排序</title> 
</head> 
<body> 
<script src="jquery-1.7.2.min.js"></script> 
<script> 
var yearArray = new Array(2009, 2009, 2008, 2010, 2009, 2010); 
$.unique(yearArray.sort()); 
console.log(yearArray);//2010,2009,2008 
</script> 
</body> 
</html>
Copy after login

I believe you have mastered the method after reading the above introduction. For more exciting information, please pay attention to php Chinese website Other related articles!

Related reading:

Implementation steps for PHP cache optimization using memcached and xcache

How about JS bubbling events Using

How to implement asynchronous synchronous requests in AJAX

The above is the detailed content of Use jQuery to deduplicate and sort arrays. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template