JS 判断数组里是否有重复项
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JS判断数组中是否有重复元素的方法</title> </head> <body> <script type="text/javascript"> var repeatArr = new Array(); repeatArr.push(1); repeatArr.push(2); repeatArr.push(2); repeatArr.push(3); var nary = repeatArr.sort(); for (var i = 0; i < repeatArr.length; i++) { if (nary[i] == nary[i + 1]) { alert("有重复:" + nary[i]); } } </script> </body> </html>