统计一段英文中各个单词出现的次数
<!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