方法1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<scrpit>
//方法1
var arr = [1,2,3,3,5,2,1,6]
var arr2 = []
for(var i=0;i<arr.length;i++){
if(arr2.indexOf(arr[i])=== -1){
arr2.push(arr[i])
}
}
console.log(arr,arr2)
</script>
</body>
</html>
方法2
// 方法2
var obj = {}
for(var a=0;a<arr.length;a++){
obj[arr[a]] = "随便"
}
console.log(obj)
var arr2 = []
for (var a in obj){
arr2.push(a-0)
}
console.log(arr2)
方法3
// 方法3 set结构
var set1 = new Set(arr)
console.log(set1)
var arr1 = Array.from(set1)
console.log(arr1)
标签:arr,log,JavaScript,---,set1,数组,var,arr1,方法
From: https://blog.csdn.net/weixin_58694594/article/details/142406469