也是用jquery的$.inArray方法
var arr=[0,2,3,5,6,9,2]; var new_arr=[]; for (var i=0;i<arr.length;i++) { var items = arr[i]; //判断元素是否存在于new_arr中,如果不存在则插入到new_arr的最后 if ($.inArray(items,new_arr) == -1) { new_arr.push(items); } }
参考博客:
jquery删除数组中重复元素_jquery_脚本之家
https://www.jb51.net/article/99104.htm