Open this example in the interactive library
Source code
console.log([..."one two one".matchAll(/one/g)].map((m) => m.index));
Sample output
[ 0, 8 ]

Find all word positions. A self-contained example using the JavaScript runtime.
Open this example in the interactive library
console.log([..."one two one".matchAll(/one/g)].map((m) => m.index));
[ 0, 8 ]