You are trying to read a string as an array. Char to char. It seems that JS does not allow changing the value of any index in this case. If you do something like: number = "12345", the value in the index: (I) will change. However, this will not solve your goal. To do what you are trying to do, you have to divide the number and then iterate over and change.
Example:
function change(s) { var number = s.replace(/\s+/g, ''); var sArr = number.split(""); for (var i = 0; i < number.length ; i++) { console.log(sArr[i]);
source share