Hello all! I was working through the list of additional methods and came across some issues when trying to use the .matchAll() method. I typed in console.log(‘Codecademy’.matchAll(‘eca’)); and it gave me an error. Please let me know whether I am doing something incorrectly or this is a bug. Thanks!
What is the error you are getting? Please post your code sample.
matchAll must accept a RegExp object with flag /g.
You can convert a string to RegExp with help new RegExp. Or instead of ‘eca’ write /eca/g. Example:
const regex = new RegExp(‘eca’, ‘g’);
const result = […‘Codecademy’.matchAll(/eca/g)];
console.log(result);
or
const result = […‘Codecademy’.matchAll(/eca/g)];
console.log(result);