240
世界上有2种人,一种懂二进制,另一种不懂二进制。

ES6-解构表达式

1】数组解析

复制代码
let arr = [1,2,3];
//以前我们想获取其中的值,只能通过角标
// let a = arr[0]
// let b = arr[1]
// let c = arr[2];
    //ES6可以这样,a,b,c 将与arr中每个位置对应来取值

    let [a,b,c] = arr;
//用一个变量代替数组下标索引位置的元素‘ console.log(a,b,c)
复制代码

 

2】对象解构

复制代码
const person = {
            name: "jack",
            age: 21,
            language: ['java', 'js', 'css']
        }
        //解构表达式获取值,将person里面的每个属性和左边对应赋值
        //const { name, age, language } = person;
        //等于下面
        //以前的写法
        //         const name = person.name;
        //         const age = person.age;
        //         const language = person.language;

        //或者将name值给abc
        const { name: abc, age, language } = person;
        console.log(abc, age, language)
        //console.log(name, age, language)
复制代码

 

 

 

 

3】箭头函数解构表达式运用

 

复制代码
    //以前
    function hello(person) {
      console.log("hello" + person.name)
    }
    hello(person); //helloqiyue
    //箭头函数
    let hello2 = params => console.log("hello" + person.name)
    hello2(person) //helloqiyue
    //箭头函数加解构表达式
//用一个参数代替对象里的属性,来直接用其属性取代对象点属性名

    var hello3 = ({ name }) => console.log("hello" + name)
    hello3(person) //helloqiyue
复制代码

 

posted @   _Origin  阅读(62)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示