TypedArray join()
JavaScript TypedArray join()方法
JavaScript
join()方法用于将Array的所有元素连接到字符串中。元素将由指定的分隔符分隔。默认的分隔符是逗号(,)。
语法:
参数:
它是可选的,可以用作参数,也可以不将其默认值为(,)。
返回值:
它返回包含数组元素集合的String。
浏览器支持:
浏览器 |
版本 |
Chrome |
1.0 |
Edge |
是 |
Firefox |
1.0 |
Opera |
是 |
示例
JavaScript TypedArray join()方法
<script type="text/javascript">
// JavaScript to illustrate join() method
// input array
var lidihuo = ['core java','C'];
//joins the elements of the array.
document.write("joins the elements of the array <br>");
document.write(lidihuo.join());
document.write("<br>");
//elements are seperated by dot (.).
document.write("elements are seperated by dot (.) <br>");
document.write(lidihuo.join('.'));
document.write("<br>");
//elements are seperated by hyphen (-).
document.write("elements are seperated by hyphen (-)<br>");
document.write(lidihuo.join('-'));
// expected output: arr[core javaC
//core java.C
//core java-C]
</script>
输出:
core Java,C
core java.C
core Java-C