Skip to content
Advertisement

Trying to convert an Array to String (JavaScript)

I am trying to convert an array to string using array.join() or array.toString() but it’s not working as it’s supposed to work. When I console.log it stays as an array.

I’ve the intuition that this issue comes from something related to function scopes, but I could not figure it out yet.

The project I’m trying to build is a password generator.

JavaScript
JavaScript

Advertisement

Answer

Array.prototype.join() returns a string. It does not change the object it is called on.

You may want to create a new variable or mutate password after the for loop has completed like so:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement