四. 对象方法的扩展

// 声明对象
const school = {
    name: "上海华师大",
    cities: ['上海','北京','深圳'],
    skill: ['java','php','vue']
}

Object.keys(school)                  //  ["name", "cities", "skill"]

Object.values(school)               //  ["上海华师大", Array(3), Array(3)]

Object.entries(school)              // [ ["name", "上海华师大"]
                                         ["cities", Array(3)]
                                         ["skill", Array(3)]
                                        ]

new Map(Object.entries(school))     // Map(3) {"name" => "上海华师大", "cities" => Array(3), "skill" => Array(3)}

const m = new Map(Object.entries(school))

m.get('cities')                     // ["上海", "北京", "深圳"]

Object.getOwnPropertyDescriptors(school)

posted @ 2020-11-26 13:26  小蓉儿  阅读(71)  评论(0编辑  收藏  举报