String.prototype.matchAllintermediateconst str = 'a1 b2 c3'
const matches = [...str.matchAll(/(w)(d)/g)]
matches.length // β 3
matches[0][1] // β 'a'Use matchAll() with the g flag to iterate over all regex matches and access capture groups in each result.
Each match result has an index property indicating where the match starts.
Challenge: Implement matchIndices(str, ch) that returns an array of indices where ch occurs.
matchIndices('abacaba', 'a') // β [0, 2, 4, 6]