Count Occurrences Of Element In Array Javascript Iterations