<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
<script type="text/javascript">
// 解构赋值 结构性赋值
let arr = [1, 2, [4, 5]];
let a = arr[0];
let b = arr[1];
let c = arr[2];
let [d, e, [f, g]] = arr;
console.log(d, e, f, g);
// let [name, title] = ['李', '歌手', 18];
let [name, , age] = ['李', '歌手', 18]; // 若想忽略数组的某个元素对变量进行赋值,可以使用逗号来间隔处理
// let [name, title] = ['李'];
console.log(name, age);
// rest参数. 使用rest 来接收赋值数组的剩余元素,但是要确保 rest 参数是要放在被赋值变量的最后一个位置上
let [name1, name2, ...rest] = ['张三', '李四', '王五', '赵六'];
console.log(rest);
</script>
</body>
</html>
上述运行结果: