Eskillsfy

Home / Blog / Text

Text · 23 Nov 2026

Word Frequency Counter: how it works and how to build one

Count how often each word or phrase appears. This guide explains what happens behind the button and shows the code, so you can build your own.

What it does

Lists the most used words or 2 and 3-word phrases with counts and percentages. Skip common words like ‘the’ and ‘and’ to see what a text is really about. Useful for SEO keyword checks and editing.

When to use it

  • SEO keyword density
  • Spotting overused words when editing
  • Analysing survey answers

How to use it

  1. Paste text or open a file.
  2. Choose words or phrases and filters.
  3. Read or copy the table.

Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/word-frequency

How it works

The counter lower-cases the text, pulls out words with a Unicode-aware regex (\p{L} matches letters in any language), optionally drops common ‘stop words’, and counts each one in a Map.

For phrases (n-grams), it slides a window of 2 or 3 words along the list and counts each joined phrase.

Build it yourself

Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.

frequency.ts (ts)

const STOP = new Set(["the", "and", "a", "to", "of", "in", "is", "it", "for", "on"]);

export function frequency(text: string, n = 1) {
  const words = (text.toLowerCase().match(/[\p{L}\p{N}']+/gu) ?? []).filter((w) => !STOP.has(w));
  const counts = new Map<string, number>();
  for (let i = 0; i + n <= words.length; i++) {
    const key = words.slice(i, i + n).join(" ");
    counts.set(key, (counts.get(key) ?? 0) + 1);
  }
  return [...counts].sort((a, b) => b[1] - a[1]);
}

Make it production-ready

  • Stem words so ‘run’ and ‘running’ count together.
  • Draw a bar chart of the top 20.

Questions

Is it case-sensitive?

No. Words are counted in lower case.

Try the Word Frequency Counter

Free, runs in your browser, nothing is uploaded.

Open it
Keep reading

More in Text

All posts