I have a STRING and I want to replace some character, and this characters are in an array. Here is my code :
let arrayParam = [];
arrayParam.push('X');
arrayParam.push('Y');
arrayParam.push('Z');
let stringToFilter = 'Y0000000';
let stringFiltered;
for (let i = 0; i < arrayParam.length; i++) {
stringFiltered = stringToFilter.replace(arrayParam[i], '');
console.log(`array:${arrayParam[i]} stringFiltered:${stringFiltered}`);
};
This result in the console :
element:A stringFiltered : Y0000000
element:B stringFiltered : 0000000
element:C stringFiltered : Y0000000
I don't understand, my var is declared outside the loop why it doesn't remember the change ?
"Y00..".replace("X"," ")return Y00...