<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="block"></div>
<script>
// 数组中的重复出现的次数
let nums = [1,2,5,8,2,2]
function mapcountFun(nums) {
let map = new Map()
console.log(map)
for(let i=0;i<nums.length;i++) {
let num = nums[i]
let count = map.get(num)
if(count) {
map.set(num,count+1)
} else {
map.set(num,1)
}
}
// 如果要取出现的次数 map.get(2)
return map
}
mapcountFun(nums)
</script>
</body>
</html>