<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test_array.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">
//合并数组
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
var arr2 = new Array(3)
arr2[0] = "James"
arr2[1] = "Adrew"
arr2[2] = "Martin"
document.write("1.合并数组"+arr.concat(arr2))
document.write("<br/>")
//数组连接
var arr = new Array(3);
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write("2.数组连接 "+arr.join(","));
//结果:George,John,Thomas
document.write("<br/>")
//数组排序
var arr = new Array(6)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
arr[3] = "James"
arr[4] = "Adrew"
arr[5] = "Martin"
document.write("3.数组连接 "+arr.sort())
//结果:Adrew,George,James,John,Martin,Thomas
document.write("<br/>")
//pop 删除并返回数组的最后一个元素
var arr4 = new Array()
arr4[0] = "George"
arr4[1] = "John"
arr4[2] = "Thomas"
arr4[3] = "James"
arr4[4] = "Adrew"
document.write("4.pop操作前 "+arr4.join())
var last = arr4.pop();
document.write("<br/>")
document.write("pop操作后 "+arr4.join())
document.write("<br/>")
//push 向数组的末尾添加一个或更多元素,并返回新的长度
var arr4 = new Array()
arr4[0] = "George"
arr4[1] = "John"
arr4[2] = "Thomas"
document.write("5.push操作前 "+arr4.join())
var size = arr4.push("Adrew","hello","ds");
document.write("<br/>")
document.write("push操作后 "+arr4.join())
document.write("<br/>")
//颠倒数组中元素的顺序。
var arr4 = new Array()
arr4[0] = "George"
arr4[1] = "John"
arr4[2] = "Thomas"
document.write("6.reverse()操作前 "+arr4.join())
var size = arr4.reverse();
document.write("<br/>")
document.write("reverse()操作后 "+arr4.join())
document.write("<br/>")
//删除并返回数组的第一个元素
var arr4 = new Array()
arr4[0] = "George"
arr4[1] = "John"
arr4[2] = "Thomas"
document.write("6.shift()操作前 "+arr4.join())
var size = arr4.shift();
document.write("<br/>")
document.write("shift()操作后 "+arr4.join())
document.write("<br/>")
//从某个已有的数组返回选定的元素
//http://www.w3school.com.cn/jsref/jsref_slice_array.asp
var arr4 = new Array()
arr4[0] = "George"
arr4[1] = "John"
arr4[2] = "Thomas"
arr4[3] = "James"
arr4[4] = "Adrew"
arr4[5] = "Martin"
document.write("7.slice()操作前 "+arr4.join())
var arr6 = arr4.slice(2,4);
document.write("<br/>")
document.write("slice()操作后的数组 "+arr6.join())
document.write("<br/>")
//删除元素,并向数组添加新元素。
//http://www.w3school.com.cn/jsref/jsref_slice_array.asp
var arr4 = new Array()
arr4[0] = "George"
arr4[1] = "John"
arr4[2] = "Thomas"
arr4[3] = "James"
arr4[4] = "Adrew"
arr4[5] = "Martin"
document.write("7.slice()操作前 "+arr4.join())
var arr6 = arr4.slice(2,4);
document.write("<br/>")
document.write("slice()截取的数组 "+arr6.join())
document.write("<br/>")
/*执行结果:
1.合并数组George,John,Thomas,James,Adrew,Martin
2.数组连接 George,John,Thomas
3.数组连接 Adrew,George,James,John,Martin,Thomas
4.pop操作前 George,John,Thomas,James,Adrew
pop操作后 George,John,Thomas,James
5.push操作前 George,John,Thomas
push操作后 George,John,Thomas,Adrew,hello,ds
6.reverse()操作前 George,John,Thomas
reverse()操作后 Thomas,John,George
6.shift()操作前 George,John,Thomas
shift()操作后 John,Thomas
7.slice()操作前 George,John,Thomas,James,Adrew,Martin
slice()操作后的数组 Thomas,James
7.slice()操作前 George,John,Thomas,James,Adrew,Martin
slice()截取的数组 Thomas,James
*/
</script>
</head>
<body>
</body>
</html>