join()
定义:join() 方法用于把数组中的所有元素转换一个字符串。
元素是通过指定的分隔符进行分隔的。
语法:array.join(separator)
eg1:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var energy = fruits.join();
var energy = fruits.join();
energy输出结果:
Banana,Orange,Apple,Mango
eg2:
使用不同的分隔符:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var energy = fruits.join(" and ");
var energy = fruits.join(" and ");
energy 结果输出:
Banana and Orange and Apple and Mango