JavaScript
const countOccurrences = (str, char) => [...str].reduce((a, v) => (v === char ? a + 1 : a), 0)
const countOccurrences = (str, char) => str.split('').reduce((a, v) => (v === char ? a + 1 : a), 0)
const countOccurrences = (str, char) => [...str].filter((item) => item === char).length
const countOccurrences = (str, char) => str.split('').filter((item) => item === char).length
TypeScript
const countOccurrences = (str: string, char: string): number => [...str].reduce((a, v) => (v === char ? a + 1 : a), 0)
const countOccurrences = (str: string, char: string): number => str.split('').reduce((a, v) => (v === char ? a + 1 : a), 0)
const countOccurrences = (str: string, char: string): number => [...str].filter((item) => item === char).length
const countOccurrences = (str: string, char: string): number => str.split('').filter((item) => item === char).length
Examples
countOccurrences('a.b.c.d.e', '.')