Skip to main content

Command Palette

Search for a command to run...

JavaScript: Get the count of a character repeated in a given string

Updated
•1 min read•View as Markdown
JavaScript: Get the count of a character repeated in a given string
H

Full stack developer (ReactJS, NodeJS, JavaScript, PHP, SQL)

const mainStr = 'str1,str2,str3,str4strings';
const repeatedStringCount = [...mainStr].filter(l => l === 's').length;

console.log(repeatedStringCount);
Output:
6

Execute above code here

More from this blog

E

Everyday Dev Patterns

26 posts

A collection of real-world JavaScript snippets, patterns, and gotchas from my day-to-day work.