var myArray = [
“Frank”,
“Paul”,
“Peter”,
“Adam”
];
// This logs to the console “Adam,Frank,Paul,Peter”
console.log(myArray.sort());
// This logs to the console “Peter,Paul,Frank,Adam”
console.log(myArray.reverse());
The join method is similar to the toString method, in that it outputs your array as a string. However, with the join method, you are able to specify which character you want to use as the delimiter, where the toString method forces a comma. By using the join method instead of the toString method, we are able to force a space in between our elements, as can be seen in the example below: