-4

how can I find the times that 1 (for example) is repeated in this array?

myArray = [1, 2, 3, 1, 4, 5, 1, 6];
Mohammad Usman
  • 37,952
  • 20
  • 92
  • 95
sqmu 7879
  • 1
  • 2
  • 5
    Please go read [ask]. You are not supposed to ask basic “how can I” questions here, but to do some initial research, and ideally based on that also try something, yourself first. – 04FS Mar 27 '19 at 12:05

1 Answers1

1

Try this solution

 function getOccurrence(myArray, value) {
        var count = 0;
        myArray .forEach((val) => (val === value && count++));
        return count;
    }
Seba Cherian
  • 1,755
  • 6
  • 18