Write the Code. Cha|

Kang_kin

园龄:4年5个月粉丝:2关注:9

解构的简单使用

  1. 将name,age提取出来,剩余的放到新对象中
student={
    "name": "Kang",
    "age":19,
    "location":{
        "address": "阿伯",
        "city": "相关",
        "state": "a"
    },
    "website": "www.kang"
}

const {name, age,...obj}=student
  1. 获取数组下的对象
country = {
    "name": "国家", "content": "内容",
    "comments": [{
        "names": "中国", "province": {
            "id": 1, "name": "北京"
        }
    }, {
        "names": "美国", "province": {
            "id": 1, "name": "纽约"
        }
    }]
}

// 获取第一个对象,在数组中加入,代表第二个对象
const {
    comments:[{
        names, province: {
            name
        }
    }]
} = country

# 获取第一个数组元素
const {names,province:{id}}= country.comments[0]

本文作者:Kang_kin

本文链接:https://www.cnblogs.com/kangkin/p/17412656.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Kang_kin  阅读(12)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起