in this piece of code:
function change(s)
{
var number = s.replace(/\s+/g, '');
for(var i = 0; i < number.length ; i++)
{
console.log(number[i]); //Line1
number[i] = '1';
console.log(number[i]); //Line2
}
}
the results of Line1 and Line2 are both the same(they return "2") ! what is going on here?!
Strings in JavaScript are immutable. You can't change them so this line does nothing
number[i] = '1';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With