I have a string, and a list of words in an array.
What I want to do is say "If any words in this array are in the string, remove them" and then "remove an double spaces from the string"
I'm almost there, but for some reason it's not paying attention to the dash
const name = "My Awesome T-Shirt Something Else" ;
const words = [
'V-Neck ',
'Long Sleeve ',
'T-Shirt ',
'Pullover Hoodie ',
'Raglan Baseball Tee ',
'Tee ',
'Zip Hoodie ',
'Tank Top ',
'Premium ',
'Sweatshirt ',
'PopSockets Grip and Stand for Phones and Tablets ',
'Shirt '
];
let newName = name;
words.forEach(w => {
if(name.includes(w)) newName = name.replace(w, '');
});
newName = newName.replace(/ +(?= )/g,'');
console.log(newName)
This returns My Awesome T-Something Else