Joining Arrays and String with the join() and concat() Method

Here's another common array and string manipulation that is commonly used and often neglected since many programmers forget that there is a method that already exists and does this function. The method we are talking about is the join() and concat() method. These two methods both combines strings and arrays into one.

The first we are going to tackle about is the join() method. So you might ask, what does the join() method do? Easy it joins all the items in the array into one string.

Code

The variable names will contain a string of all the elements found on the dataArray. The default value in joining them or if you don't want to place a parameter, the elements will be separated with a comma ",". On the other hand if you want to separate it with something like say a ":" or a string like "and" all you have to do is place a parameter inside the method.