当前位置:网站首页>软通乐学-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]+'次');
};

边栏推荐
- 日期加1天
- Write web games in C language
- QT implementation window gradually disappears qpropertyanimation+ progress bar
- Click QT button to switch qlineedit focus (including code)
- 1323. Maximum number of 6 and 9
- Remove the border when input is focused
- 指定格式时间,月份天数前补零
- QT style settings of qcobobox controls (rounded corners, drop-down boxes, up expansion, editable, internal layout, etc.)
- C basic grammar
- Codeforces - 1526C1&&C2 - Potions
猜你喜欢

QT realizes window topping, topping state switching, and multi window topping priority relationship

The concept of C language array

Codeforces Round #799 (Div. 4)A~H

QT implementation window gradually disappears qpropertyanimation+ progress bar

Remove the border when input is focused

(POJ - 3685) matrix (two sets and two parts)

Pyside6 signal, slot

分享一个在树莓派运行dash应用的实例。
Frida hook so layer, protobuf data analysis

Some problems encountered in installing pytorch in windows11 CONDA
随机推荐
Problem - 922D、Robot Vacuum Cleaner - Codeforces
<li>圆点样式 list-style-type
Sanic异步框架真的这么强吗?实践中找真理
875. 爱吃香蕉的珂珂 - 力扣(LeetCode)
Date plus 1 day
Opencv learning log 28 -- detect the red cup cover
Ball Dropping
Understand what is a programming language in a popular way
860. Lemonade change
QT style settings of qcobobox controls (rounded corners, drop-down boxes, up expansion, editable, internal layout, etc.)
JS call camera
拉取分支失败,fatal: ‘origin/xxx‘ is not a commit and a branch ‘xxx‘ cannot be created from it
useEffect,函数组件挂载和卸载时触发
Acwing: the 56th weekly match
Frida hook so layer, protobuf data analysis
MariaDB的安装与配置
Codeforces Round #798 (Div. 2)A~D
Luogu P1102 A-B number pair (dichotomy, map, double pointer)
1903. Maximum odd number in string
Radar equipment (greedy)