This site is mobile accessible. Press the "Tap Here" button to use a smaller font-size.

Smartphone icons created by Freepik - Flaticon

JS Strings

The matchAll() Method

ES2020 intoduced the string method matchAll().

let text = "I love cats. Cats are very easy to love. Cats are very popular.";
const iterator = text.matchAll(/Cats/g);

document.getElementById("demo").innerHTML = Array.from(iterator);

If the parameter is a regular expression, the global flag (g) must be set, otherwise a TypeError is thrown.