It returns a new array by joining the list of elements with the given delimiter/separator.
delimiter: indicates delimiter/ separator to be used while joining.
The join() method does not affect the original array.
var fruits = ["Apple", "Orange", "banana", "Grapes", "Watermelon"]; document.write(fruits, "<br/>"); document.write(fruits.join("-"))
- In the above code, we have created an array of fruits and assigned some values inside the square brackets.
- Then we printed the array “fruits” without using the join() method, So the default delimiter is a comma (,) displayed.
- If you want to add your desired delimiter symbol between the array list of values. Then you should use the join() method in JS and give value as your delimiters symbol.
- Here, we give the “-” hyphen symbol, so the hyphen is displayed between all array values.