DEV Community

joao victor
joao victor

Posted on

JavaScript Array Methods: join()

I was training on the CodeWars when I had a problem: write a function where your returns is a string of array.
Ex: ['hello', 'world'] to 'hello world'

You can use the method join() to do that for you.

The function looked like:

function arrayToString(words)
{
return words.join(" ")
}

It's so simple, alright?

The method join by default return a string separate with ',', something be like: 'hello, world', using the last example as example.

But you can separate too with spaces, just use join(" ")
The example will stay: 'hello world'.

*sorry for low level english, im studying *

Top comments (0)