js遍历出数组重复的数据,及重复的个数(简单有效)

const res={} ["s","s","a"].forEach((key)=>{ if(res[key]){ res[key]++ }else{ res[key]=1 } }) console.log(res)
posted @ 2020-04-07 15:38  前端张大碗  阅读(5746)  评论(0编辑  收藏  举报