当前位置: 首页 > 网络学院 > 客户端脚本教程 > JavaScript > JavaScript join()方法

JavaScript
JS 介绍
JS 怎样使用
JS 在哪使用
JS 变量
JS If...Else
JS Switch
JS 操作符
JS Popup Boxes
JS 函数
JS For 循环
JS While 循环
JS Break 循环
JS For...In
JS 事件
JS Try...Catch
JS Throw
JS onerror
JS 特殊字符
JS Guidelines
JS 对象介绍

JavaScript join()方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 330 ::
收藏到网摘: n/a

Definition and Usage
定义与用法

The join() method is used to put all the elements of an array into a string.
join()方法可用给数组中的所有元素加入字符串中

The elements will be separated by a specified separator.
每个元素可用指定的分隔符区分开

Syntax
语法

arrayObject.join(separator)

Parameter
参数
Description
描述
separator Optional. Specifies the separator to be used
可选项。指定要使用的分隔符号


Tips and Notes
提示与注意点

Note: Comma is the default separator for the join() method.
注意点:使用join()方法的默认分隔符号是逗号","


Example
举例

In this example we will create an array, and then put all the elements in a string:
这个举例中我们将建立一个数组,并将里面所有的元素放入字符串中:

<script type="text/javascript">
var arr = new Array(3)
arr[0] = "Jani"
arr[1] = "Hege"
arr[2] = "Stale"
document.write(arr.join() + "<br />")
document.write(arr.join("."))
</script>

The output of the code above will be:
上面代码的输出结果为:

Jani,Hege,Stale
Jani.Hege.Stale


Try-It-Yourself Demos
尝试与演示

join()
How to use join() create a string from an array.
怎样使用join()将来自数组的元素建立成字符串

评论 (0) All

登陆 | 还没注册?