Counting specific members of an array

I want to count members of an array, example:

myArray = [1, 1, 2, 1, 3, 3, 1]

I want to count all members of the array that is '1' and store it as another variable.

Thanks for the help
let count = 0;
myArray.forEach(function(item){if(item == 1) count++})

EDIT: For readability
myArray.forEach( function(item) {
if(item == 1) {
count++
}
})
let count = 0;
myArray.forEach(function(item){if(item == 1) count++})

EDIT: For readability
myArray.forEach( function(item) {
if(item == 1) {
count++
}
})
Works, thanks a lot

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/counting-specific-members-of-an-array.117986/