I have two arrays. One array contains the characters to search for and the other has the characters to replace them. I want to find all occurrences of each item in the first array within a string, and replace them with their corresponding items from the second array.
let converted = '';
let bbCodes = [
"[code]", "[/code]", "[h1]", "[/h1]"
];
let replacers = [
"<code>", "</code>", "<h1>", "</h1>"
];
let needsConverted = this.state.txtAreaVal;
bbCodes.map((code, index) => {
converted = needsConverted.replace(code, replacers[index]);
console.log(converted);
});
console.log(converted);
}
Output is not quite what I expected.