3.变量的解构赋值
<!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>Document</title>
</head>
<body>
<script>
// ES6允许按照一定模式从数组和对象中提取值,对变量进行赋值---这杯称为解构赋值
// 1.数组的解构
const NAME = ["张三", "李四", "王五", "赵六"];
let [name1, name2, name3, name4] = NAME;
console.log(name1, name2, name3, name4);
// 2.对象的解构
const zhao = {
name: "赵本山",
age: "不详",
sketch: function () {
console.log("我可以表演");
},
};
// let { name, age, sketch } = zhao; //变量名可以随便写,不用和对象里面的属性名一致
// console.log(name, age, sketch);
// sketch();
// 对于对象的方法名,解构赋值比较多
let { sketch } = zhao;
sketch();
</script>
</body>
</html>