我想知道在變量「arr」中出現次數/次數2的次數/次數,答案應該是2.如何訪問數組號碼中的數字稱爲'數字'?如何在JavaScript過濾器函數中訪問鍵值對中的數組
let arr = [{numbers:[2,2,3]}]
//how many times does the number 2 appear in the array above
let newArray = arr.filter(function(e){
return e.numbers[0] == 2
})
document.write("Occurence of two:" + newArray.length + "<br>")
感謝,嘗試解決 https://codepen.io/shihanrehman/pen/JybVJG
有兩個數組'arr'和'numbers'所以這你需要檢查數組嗎? – MaxZoom