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>
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>
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!