Grow your CSS skills. Land your dream job.

Replacing each char in string with an asterisk.

  • # October 31, 2012 at 10:49 am

    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: *******​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
    # October 31, 2012 at 11:13 am

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

    # October 31, 2012 at 11:26 am

    @senff,

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

    # October 31, 2012 at 11:33 am

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

    # October 31, 2012 at 4:13 pm

    @mmoustafa,

    BOSS! Thanks man..

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".