Posted in Javascript onMarch 31, 2021
<!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>
<div class="test"></div>
<div class="test1"></div>
<div class="test11"></div>
<div class="test2"></div>
<script>
var bcfs = []
var count = {}
var test = document.querySelector('.test')
var test1 = document.querySelector('.test1')
var test2 = document.querySelector('.test2')
var test11 = document.querySelector('.test11')
var str = '1237439746238666666666666669437'
for (let i in str){
let value = str[i]
if (bcfs.indexOf(str[i]) === -1){
bcfs.push(str[i])
}
if (!count[value]){
count[value] =1
}else{
count[value] ++
}
}
test.innerHTML = `字符串:${str}`
test1.innerHTML = `去重结果:${bcfs}`
test11.innerHTML = '重复次数:' + '<br>'
for (let i in count){
test2.innerHTML += i + '的重复次数:' + count[i] + '<br/>'
}
</script>
</body>
</html>
JavaScript 去重和重复次数统计
- Author -
蔡不蔡声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@