JavaScript join( )-筆記

  • 55
  • 0
  • ES6
  • 2018-08-27

join( ) 

The join( ) method joins the elements of an array into a string, and returns the string.

The elements will be separated by a specified separator. The default separator is comma (,).

var arr = ["George","John","Thomas"];
console.log(arr.join());

// George,John,Thomas
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var a = fruits.join(" and ");
console.log(a);

// Banana and Orange and Apple and Mango