💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
# 数组的解构 数组的解构要按照顺序来执行. ``` var [a, b] = [1, 2]; console.log(a); console.log(b); ``` ### 默认值 ``` var [a, b = 10, c] = [1, , 3]; console.log(a); console.log(b); console.log(c); ``` # 对象的解构 对象的解构不需要按照顺序来执行. ``` let {foo, bar} = {bar: 'hello', foo: 'world'}; console.log(foo); console.log(bar); ``` ### 对象属性别名 ``` let {foo: abc, bar} = {bar: 'hello', foo: 'world'}; //如果有了别名,那么foo就无效了 console.log(abc); console.log(bar); ``` ### 获取对象的方法 ``` let {length} = 'hello'; console.log(length); //5 ``` # 字符串解构 ``` let [a, b, c, d] = 'hello'; console.log(a); //h console.log(b); //e console.log(c); //l console.log(typeof d); //string类型 ```