当前位置:网站首页>软通乐学-js求字符串中字符串当中那个字符出现的次数多 -冯浩的博客
软通乐学-js求字符串中字符串当中那个字符出现的次数多 -冯浩的博客
2022-07-06 09:29:00 【冯浩(grow up)】
使用的函数:charAt():根据位置取字符串
思路:我们通过循环将字符串通过charAt通过下标找到字符,
然后存储到一个对象对象名中,然后找到对象对应的属性值,
如果有这个对象名,就进行加一,
如果没有就设置为1
最后遍历这个对象,就可以得到了
var a = "123abcdefaaaaaaaaaaaaaaaaaaaa";
// 创建一个数组用来储存元素
var obj = new Object();
// 循环整个字符串的的长度
for(var i =0;i<a.length;i++){
// charAt:根据位置取字符串
// 循环去除字符串
var value = a.charAt(i);
console.log(value);
if(obj[value]>0){
obj[value]++;
}else{
obj[value]=1;
}
}
console.log(obj);
for(var j in obj){
console.log(j+"出现的次数"+obj[j]+'次');
};

边栏推荐
- Acwing: Game 58 of the week
- Codeforces - 1526C1&&C2 - Potions
- 1013. Divide the array into three parts equal to and
- 1855. Maximum distance of subscript alignment
- Openwrt build Hello ipk
- Problem - 1646C. Factorials and Powers of Two - Codeforces
- (POJ - 3579) median (two points)
- C language must memorize code Encyclopedia
- It is forbidden to trigger onchange in antd upload beforeupload
- Codeforces - 1526C1&&C2 - Potions
猜你喜欢

Pytorch extract skeleton (differentiable)

Flag framework configures loguru logstore

Codeforces Round #802(Div. 2)A~D

Differential (one-dimensional, two-dimensional, three-dimensional) Blue Bridge Cup three body attack

1855. Maximum distance of subscript alignment

力扣——第298场周赛

本地可视化工具连接阿里云centOS服务器的redis

QT有关QCobobox控件的样式设置(圆角、下拉框,向上展开、可编辑、内部布局等)

Borg maze (bfs+ minimum spanning tree) (problem solving report)

QWidget代码设置样式表探讨
随机推荐
Acwing: Game 58 of the week
Problem - 1646C. Factorials and Powers of Two - Codeforces
Codeforces - 1526C1&&C2 - Potions
OneForAll安装使用
Luogu P1102 A-B number pair (dichotomy, map, double pointer)
860. Lemonade change
Frida hook so layer, protobuf data analysis
antd upload beforeUpload中禁止触发onchange
Problem - 922D、Robot Vacuum Cleaner - Codeforces
指定格式时间,月份天数前补零
QNetworkAccessManager实现ftp功能总结
(POJ - 2739) sum of constructive prime numbers (ruler or two points)
(POJ - 3579) median (two points)
Local visualization tools are connected to redis of Alibaba cloud CentOS server
AcWing:第58场周赛
Opencv learning log 28 -- detect the red cup cover
The "sneaky" new asteroid will pass the earth safely this week: how to watch it
Generate random password / verification code
Sword finger offer II 019 Delete at most one character to get a palindrome
628. Maximum product of three numbers