<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>arr深拷贝</title>
</head>
<body>
<script>
// 深拷贝:复制所有数据(数值类型,引用类型),和原数据完全独立。
const arr1 = [[1, 2, 3], 2, 3];
const arr_d = JSON.parse(JSON.stringify(arr1));
console.log(arr_d);
// [[1, 2, 3], 2, 3]
arr1[0].push(4);
console.log(arr1);
// [[1, 2, 3, 4], 2, 3]
console.log(arr_d);
// [[1, 2, 3], 2, 3]
</script>
</body>
</html>