Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Replacing each char in string with an asterisk.

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #40543
    JohnMotylJr
    Participant

    Been up for 30+ hours.. i’m so tired and not thinking correctly. All i’m doing is replacing each char in the string with an asterisk. Is there an easier way, or better way? What i have works but i feel that maybe a regex isn’t necessary.

    var word = "Chowder"; // Normally dynamic but for this sake, static.
    word = word.replace(/./g, "*");

    // To test
    console.log(word);
    ​// Output: *******​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
    #113034
    Senff
    Participant

    Perhaps just check the length of the string and then just write out that number of asterisks?

    #113036
    JohnMotylJr
    Participant

    @senff,

    Possibly, thanks for the logic. Ill try that and re-post..

    #113038
    mmoustafa
    Member

    console.log(Array(word.length+1).join(“*”));

    #113062
    JohnMotylJr
    Participant

    @mmoustafa,

    BOSS! Thanks man..

    #282995
    nayish
    Participant

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.