Here is my code, here i am changing arrayItem.replace("\u001bE", "") my problem is i want to change for another string also "\x1B-1" --> how to declare this in my code replacing multiple strings at a time.
const file = files[0];
let reader = new FileReader();
const fruits = [];
reader.onload = (e) => {
const file = e.target.result;
const lines = file.split(/\r\n|\n/);
//console.log(lines.length);
textarea.value = lines.join('\n');
lines.forEach(function (arrayItem) {
//console.log(arrayItem.replace("\u001bE", "<b>"));
var arr1 = arrayItem.replace("\u001bE", "<b>");
var arr2 = arr1.replace("\u001bF", "</b>");
fruits.push(arr2);
});
console.log(fruits.length);
if (parseInt(fruits.length) > 0) {
console.log(fruits);
txtreplace.innerHTML = fruits;
}
};
reader.onerror = (e) => alert(e.target.error.name);
reader.readAsText(file);
});
}, false);
1 Answer 1
Not sure if this is what you're asking but you can chain multiple calls to replace like this:
var arr1 = arrayItem.replace("\u001bE", "<b>").replace("\x1B-1", "<something>");
Sign up to request clarification or add additional context in comments.
Comments
lang-js