I have an array full of strings which I'd like to loop over and replace any occurrences of '123' with ''.
The desired result would be: ['hello', 'cats', 'world', 'dogs']
let arr = ['he123llo', 'cats', 'wor123ld', 'dogs'];
arr.forEach(x => {
x.replace('123', '');
});
const replacedStrings = arr.map(word => word.replace(/123/g, ''))forEach()returnsundefined, you're supposed to useArray.prototype.map()insted and, by the way, it's better to use.replace(/123/g, '')if you want to replace all occurrences of unneeded substring