specific word count (index of )

 

统计一段英文中各个单词出现的次数

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
var str ="Tomorrow will be better and I am best";
var arr=str.split(" ");
var map ={};
for(var i=0;i<arr.length;i++){
var strword=arr[i];
if(!map[strword]){
map[strword]=1;
}
else{
map[strword]++;
}
}
for(var word in map){
console.info(word+" "+map[word]);
}
</script>
</head>
<body>

</body>
</html>
---------------------
作者:liyldada
来源:CSDN
原文:https://blog.csdn.net/liyldada/article/details/53121075

posted @ 2018-10-30 23:18  初心丨不变  阅读(145)  评论(0编辑  收藏  举报