I have this for
loop in which I’m trying to replace an index in underlineArr
with a character and whenever I try to redefine it so It saves the current variable so I’m able to access it and change it later, nothing is being saved, It keeps using the default array while I’m trying to get the newly edited array.
For Loop:
const content = collected.content.toLowerCase();
for (let i = 0; i < underlineArr.length; i++) {
msg = underlineArr[i] = word[i] == content && underlineArr[i] == "_" ? content : "_";
}
msg = underlineArr.join(" ");
console.log(msg);
This is the underlineArr
constant: https://i.stack.imgur.com/vtzj2.png
This is the word
constant: "French Toast"
, Please note the constant is random from an array I created.
Lastly, collected.content
is just a string returned.
The output: Output
Expected output:
_ r _ _ _ _ _ _ _ _ _ _
_ r e _ _ _ _ _ _ _ _ _
_ r e n _ _ _ _ _ _ _ _
_ r e n c _ _ _ _ _ _ _
.....