$.inArray jquery(以及陣列去重)
阿新 • • 發佈:2019-01-21
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="jquery-2.1.4.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<script type="text/javascript">
function Deduplication(Array){
var newArray = [];
for(var i=0; i<Array.length; i++){
var items = Array[i];
if($.inArray(items,newArray) == -1){
newArray.push(items)
}
}
return newArray;
}
var arr = [2,4,1,4,5,6,7,6,2,3];
console.log(Deduplication(arr))
</script>
</body>
</html>