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
| // 3、遍历数组将伪数组变成真正的数组
<body>
<div></div><div></div><div></div><div></div><div></div><div></div>
<script>
var divs = document.getElementsByTagName('div');
var arr = [...divs];
console.log(arr);//[div, div, div, div, div, div]
</script>
</body>
// 4、克隆数组
let arr1 = [1,2,3,4,5];
let arr2 = [...arr1];
console.log(arr2);
/* 合并对象时,出现同名的属性,书写在后面的属性值将替换
前面的同名属性的属性值,数组却不会,因为两个数组合并下标肯定
会冲突,因此js底层做了处理 */
let obj1 = {
sex: "男"
}
let obj2 = {
sex: "nan",
...obj1,
}
let obj3 = {
...obj1,
sex: "nan",
}
console.log(obj2); // { sex: '男' }
console.log(obj3); // { sex: 'nan' }
let arr1 = [1, 2, 3, 4, 5, 6];
let arr2 = [5, 6, 7, 8];
let arr3 = [...arr1, ...arr2];
console.log(arr3); // [1, 2, 3, 4, 5, 6, 5, 6, 7, 8]
|