javascriptarrayselement

How to make elements in an array display as one word?


I am creating a random password generator. One of the arrays contains all of the elements, in order, in order to create the password, and I don't know how to do that in a way that it would be applicable to all password lengths.

ultimateRandomPassword (name of array) = ['q', '%', '8', 'v', 'o', 'F', 'A', 'M', 'Y', '9'] => q%8voFAMY9 (for output)

I wanted to do console.log(ultimateRandomPassword[1] + ultimateRandomPassword[2]...), but I know that would be incredibly inefficient, and also would only apply to a specific number of elements in the array.


Solution

  • That's quite easy, use Array#join()

    const ultimateRandomPassword = ['q', '%', '8', 'v', 'o', 'F', 'A', 'M', 'Y', '9'];
    
    console.log(ultimateRandomPassword.join(''));