题目
统计数组 arr 中值等于 item 的元素出现的次数
示例1
输入:
[1, 2, 4, 4, 3, 4, 3], 4 输出: 3
编辑
核心代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>计数</title> </head> <body> <script>function count(arr, item) { let num = 0 arr.forEach(el=>{ if(el == item){ num++ } }) return</script> </body> </html>
