-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs_array.html
More file actions
61 lines (56 loc) · 2.33 KB
/
js_array.html
File metadata and controls
61 lines (56 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!--
* @由于个人水平有限, 难免有些错误, 还请指点:
* @Author: cpu_code
* @Date: 2020-10-15 18:56:21
* @LastEditTime: 2020-10-16 21:46:19
* @FilePath: \web\javascript\js_array\js_array.html
* @Gitee: [https://gitee.com/cpu_code](https://gitee.com/cpu_code)
* @Github: [http://github.com/CPU-Code](http://github.com/CPU-Code)
* @CSDN: [https://blog.csdn.net/qq_44226094](https://blog.csdn.net/qq_44226094)
* @Gitbook: [https://923992029.gitbook.io/cpucode/](https://923992029.gitbook.io/cpucode/)
-->
<!DOCTYPE html>
<html lang="ch">
<head>
<meta charset="UTF-8">
<title>Array对象</title>
<script>
/*
Array:数组对象
1. 创建:
1. var arr = new Array(元素列表);
2. var arr = new Array(默认长度);
3. var arr = [元素列表];
3. 属性
length:数组的长度
4. 特点:
1. JS中,数组元素的类型可变的。
2. JS中,数组长度可变的。
*/
//1.创建方式1
var arr1 = new Array(1,2,3);
var arr2 = new Array(5);
var arr3 = [1,2,3,4];
var arr4 = new Array();
document.write(arr1 +"<br>");
document.write(arr2 +"<br>");
document.write(arr3 +"<br>");
document.write(arr4 +"<br>");
var arr = [1,"cpu",true];
document.write("arr = " + arr + "<br>");
document.write("arr[0] = " + arr[0] + "<br>");
document.write("arr[1] = " + arr[1] + "<br>");
document.write("arr[2] = " + arr[2] + "<br>");
document.write("arr[10] = " + arr[10] +"<br>");
arr[10] = "cpucode";
document.write("arr[10] = " + arr[10] +"<br>");
document.write("arr[9] = " + arr[9] +"<br>");
document.write("arr.length = " + arr.length + "<br>");
// join(参数):将数组中的元素按照指定的分隔符拼接为字符串
document.write(arr.join("---") + "<br>");
// push() 向数组的末尾添加一个或更多元素,并返回新的长度
arr.push(11);
document.write(arr.join("---") + "<br>");
</script>
</head>
</html>