By using filter method
let sampleArray = [5, 5, 2, 4, 5];
let largestNumber = Math.max(...sampleArray);
let count = sampleArray.filter(number => number === largestNumber).length;
console.log("Count of Largest numbers in the Array : ", count);
// Count of Largest numbers in the Array : 3
By using reduce method
let sampleArray = [5, 5, 2, 4, 5];
let largestNumber = Math.max(...sampleArray);
let result = sampleArray.reduce((count, currentValue) => {
return count + (currentValue === largestNumber)
},0);
console.log("Count of Largest numbers in the Array : ", result);
// Count of Largest numbers in the Array : 3