一、数组的合并
const arr1 = ['周星驰', '周杰伦', '周华健'];
const arr2 = ['刘德华', '周润发', '张学友'];
const arr3 = [...arr1, ...arr2];
console.log(arr3);
输出结果
二、数组的克隆(浅拷贝)
const arr1 = ['周星驰', '周杰伦', '周华健'];
const arr2 = [...arr1];
console.log(arr2);
输出结果
三、伪数组转换为真正的数组
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>测试</title>
</head>
<body>
<div>1</div>
<div>2</div>
<div>3</div>
<script>
const divs = document.querySelectorAll('div');
const arr = [...divs];
console.log(arr);
</script>
</body>
</html>
输出结果
网友评论