arashi-sho

1.字符串统计出现次数

let str="helloword?no.thank"
const obj={}
for(let item of str){
  obj[item]=obj[item]+1 || 1
}
console.log(obj)

2.数组统计出现次数

let arr = [\'vs\',\'code\',\'coed\',\'vs\']
let countArr=arr.reduce(function(all,item){
  if(item in all){
    all[item]++
  }else{
    all[item]=1 
  }
  return all
},{})
console.log(countArr)

 

分类:

技术点:

相关文章:

  • 2021-12-28
  • 2021-09-04
  • 2021-11-29
  • 2021-12-28
  • 2021-11-02
  • 2021-11-29
  • 2021-12-28
  • 2021-12-13
猜你喜欢
  • 2021-07-15
  • 2021-12-29
  • 2021-12-28
  • 2021-11-29
  • 2021-11-29
  • 2021-12-28
  • 2021-12-09
相关资源
相似解决方案