I'm trying to add a very simple method to the String object:
String.prototype.double = function double() {
let newStr = ""
for (let char of this) {
console.log(char)
newStr += char;
newStr += char;
}
}
As you can see, it just "doubles" each character in the string. The problem is, i don't know how to actually replace the original string, with the new one("newStr")
I've tried doing this = newStr, which resulted in an "Invalid left-hand side in assignment" error.
How can i replace the original string, on which the method was called, with the new one?