Looping over string

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?

cons…


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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Looping over string." Babacar Diakite | Sciencx - Wednesday August 7, 2024, https://www.scien.cx/2024/08/07/looping-over-string/
HARVARD
Babacar Diakite | Sciencx Wednesday August 7, 2024 » Looping over string., viewed ,<https://www.scien.cx/2024/08/07/looping-over-string/>
VANCOUVER
Babacar Diakite | Sciencx - » Looping over string. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/07/looping-over-string/
CHICAGO
" » Looping over string." Babacar Diakite | Sciencx - Accessed . https://www.scien.cx/2024/08/07/looping-over-string/
IEEE
" » Looping over string." Babacar Diakite | Sciencx [Online]. Available: https://www.scien.cx/2024/08/07/looping-over-string/. [Accessed: ]
rf:citation
» Looping over string | Babacar Diakite | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.