This content originally appeared on DEV Community and was authored by Babacar Diakite
Good day. I am attempting to iterate over a string and mask each word with an odd index. The following is my current approach, but I am not yet achieving the desired outcome. Could anyone kindly assist me in identifying the source of the issue?
const test =
"Living in that house and using the pool would be like a summer vacation, not a job";
const stringLitertor = (data) => {
data.split(" ").forEach((word, index) => {
if ((word[index] = index % 2) !== 0) {
word.replace(word, "****");
}
});
return data;
};
console.log(stringLitertor(test));
This content originally appeared on DEV Community and was authored by Babacar Diakite
Babacar Diakite | Sciencx (2024-08-07T01:46:40+00:00) Looping over string. Retrieved from https://www.scien.cx/2024/08/07/looping-over-string/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.