例子,javascript数组连接 concat方法的例了。
复制代码 代码示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Javascript数组连接 concat方法 - www.jb200.com</title>
<script type="text/javascript">
window.onload = function () {
var arr = ["ronaldo", "rivaldo", "backham", "limin"];
ShowArray(arr);
//返回连接后的数组
var arr2 = arr.concat("lijingzhi", ["lixuefen", "yangyuexian"]);
ShowArray(arr2);
}
function ShowArray(arr) {
var output = "";
for (var i = 0; i < arr.length; i++) {
if (output == "") {
output = arr[i];
}
else {
output += "," + arr[i];
}
}
alert(output);
}
</script>
</head>
<body>
</body>
</html>