当前位置:网站首页>Soft music -js find the number of times that character appears in the string - Feng Hao's blog
Soft music -js find the number of times that character appears in the string - Feng Hao's blog
2022-07-06 16:39:00 【Feng Hao (grow up)】
Functions used :charAt(): Take the string according to the position
Ideas : We loop the string through charAt Find the character by subscript ,
Then it is stored in an object object name , Then find the attribute value corresponding to the object ,
If there is this object name , Just add one ,
If not, set it to 1
Finally, traverse this object , You can get it
var a = "123abcdefaaaaaaaaaaaaaaaaaaaa";
// Create an array to store elements
var obj = new Object();
// Loop the length of the entire string
for(var i =0;i<a.length;i++){
// charAt: Take the string according to the position
// Loop to remove string
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+" Number of occurrences "+obj[j]+' Time ');
};

边栏推荐
- 原生js实现全选和反选的功能 --冯浩的博客
- Codeforces round 797 (Div. 3) no f
- 第5章 消费者组详解
- input 只能输入数字,限定输入
- Market trend report, technological innovation and market forecast of desktop electric tools in China
- 第6章 DataNode
- 简单尝试DeepFaceLab(DeepFake)的新AMP模型
- Market trend report, technical innovation and market forecast of tabletop dishwashers in China
- 解决Intel12代酷睿CPU【小核载满,大核围观】的问题(WIN11)
- Tert butyl hydroquinone (TBHQ) Industry Research Report - market status analysis and development prospect forecast
猜你喜欢

QT模拟鼠标事件,实现点击双击移动拖拽等

Base dice (dynamic programming + matrix fast power)

业务系统从Oracle迁移到openGauss数据库的简单记录

Raspberry pie 4b64 bit system installation miniconda (it took a few days to finally solve it)

Anaconda下安装Jupyter notebook

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

300th weekly match - leetcode

Discussion on QWidget code setting style sheet

新手必会的静态站点生成器——Gridsome

QT realizes window topping, topping state switching, and multi window topping priority relationship
随机推荐
QT implementation fillet window
Spark独立集群动态上线下线Worker节点
Install Jupiter notebook under Anaconda
QT implementation window gradually disappears qpropertyanimation+ progress bar
(lightoj - 1370) Bi shoe and phi shoe (Euler function tabulation)
China double brightening film (dbef) market trend report, technical dynamic innovation and market forecast
The concept of spark independent cluster worker and executor
The "sneaky" new asteroid will pass the earth safely this week: how to watch it
Codeforces Round #802(Div. 2)A~D
Browser print margin, default / borderless, full 1 page A4
China tetrabutyl urea (TBU) market trend report, technical dynamic innovation and market forecast
Market trend report, technological innovation and market forecast of China's double sided flexible printed circuit board (FPC)
875. 爱吃香蕉的珂珂 - 力扣(LeetCode)
(lightoj - 1369) answering queries (thinking)
原生js实现全选和反选的功能 --冯浩的博客
Spark的RDD(弹性分布式数据集)返回大结果集
Raspberry pie 4b64 bit system installation miniconda (it took a few days to finally solve it)
Input can only input numbers, limited input
Research Report on hearing health care equipment industry - market status analysis and development prospect prediction
Date plus 1 day