OK, I know if I have say the character '-' and I want to remove it in all places in a string with JavaScript, I simply ...
someWord = someWord.replace(/-/g, '');
But, when applying this to an array of characters, it s not working ...
const badChars = ('\/:*?"<>|').split('');
let fileName = title.replace(/ /g, '-').toLocaleLowerCase();
for (let item = 0; item < badChars.length; item++) {
// below will not work with global '/ /g'
fileName = fileName.replace(/badChars[item]/g, '');
}
Any ideas?
const badChars = /[\/:*?"<>|]/g;