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

JavaScript
JS数学对象参考
JS字符串对象参考
JS函数参考
JS事件参考
Javascript 常用正则表达式
FF和IE下的js兼容性问题
jQuery 简单介绍
jQuery / 核心 / $(expression, [context] ) 函数
jQuery / 核心 / $(html) 函数
如何使用JS来判断浏览器类型(ie、firefox,等等)
Javascript在IE和FireFox中的不同表现
3个js字符编码函数区别
javascript 中的 XMLDOM 对象

JavaScript join()方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 331 ::
收藏到网摘: 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

登陆 | 还没注册?