标签:
1.判断一个字符串中出现次数最多的字符,统计这个次数
var str = ‘absdfdfsdfsdf‘; function aa(str){ var obj = {}, key = 0; for(var i=0; i<str.length; i++){ key = str.charAt(i); if(obj[key]){ obj[key]++; }else{ obj[key] = 1; } } var m = 0, i = 0; for(var key in obj){ if(obj[key] > m){ m = obj[key]; i = key; } } console.log(i , m) }
2.截取字符串abcdefg的efg
var str = "abcdefg";
var idx = str.indexOf("efg");
var efg = str.substr(str.indexOf("efg"), 3);
alert(efg);
标签:
原文地址:http://www.cnblogs.com/vivijs/p/4450004.html