counting how many times an item appears in a multidimensional array in javascript
问题 Given a multidimensional array like this: var arr = [ "apple", ["banana", "strawberry","dsffsd", "apple"], "banana", ["sdfdsf","apple",["apple",["nonapple", "apple",["apple"]]]] ,"apple"]; the challenge was to write a function that keeps the array and an item as arguments and return how many times that item appears in the array. My first solution did the trick: function countItems(arr, item, sumarr = []) { // sumarr = array to store items matched for (let i = 0; i < arr.length; i++ ){ //