Text Keyword Density

Keyword Density Checker






Please enter both text and keyword

'; return; } // Count the number of times the keyword appears in the text const keywordRegex = new RegExp(`\\b${keyword}\\b`, 'gi'); const keywordCount = (text.match(keywordRegex) || []).length; // Calculate the density of the keyword const density = (keywordCount / text.split(' ').length) * 100; // Display the density percentage responseDiv.innerHTML = `

Keyword density: ${density.toFixed(2)}%

`; // Highlight the keyword in the text const highlightedText = text.replace(keywordRegex, `${keyword}`); document.getElementById('text').innerHTML = highlightedText; }