<script> const a= 'hello world'; const b =a.replace(/\s/gi,'').split(""); console.log(b); //去掉空字符的方法是replace(/\s/gi,''); //split将字符串切割成数组形式; var obj = {} for (const value of a) { if(!(value in obj)){ obj[value] = 1 }else { obj[value] ++ } } console.log(22,obj) </script>
标签:字符,obj,..,编程,value,replace,字符串,const From: https://www.cnblogs.com/baoxinyu/p/16649116.html