解构赋值 // 解构赋值 // let arr = [1, 2, 3]; // let a = arr[0]; // let b = arr[1]; // let c = arr[2]; // console.log(a, b, c); // 数组的结构赋值 // let [a, b, c] = [1, 2, 3]; // console.log(a, b, c); // 对象的解构赋值 // :可以起个别名 // =表示默认值 // let { // name: userName, // sex, // age = 18 // } = { // name: "along", // sex: "M", // age: 30 // }; // console.log(userName, age); let [arr, str, obj] = [ [2, 4, 6], "hello word", { city: "beijing", address: "北三环" } ] console.log(arr); console.log(str); console.log(obj); let [ [num1, num2, num3], str, { city } ] = [ [2, 4, 6], "hello word", { city: "beijing", address: "北三环" } ] console.log(num3); console.log(str); console.log(city); let [ [, , num3], str, { city } ] = [ [2, 4, 6], "hello word", { city: "beijing", address: "北三环" } ] console.log(num3); console.log(str); console.log(city); // 解构应用 function ajax({ url = new Error(), method = "get",//默认值 data = {} }) { console.log(method); } ajax({ url: "", method: "post" });