先建个对象
// 声明对象
const company = {
brand:'yinsui',
cities:['Urumchi','ningbo','hangzhi','zhoushan'],
service:['gongshang','shuwu','peixun','shengji']
}
Object.values
Object.values() 方法返回一个给定对象的所有可枚举属性值的数组;
// 获取对象所有键
console.log(Object.keys(company)); // ['brand', 'cities', 'service']
console.log(Object.values(company)); // ['yinsui', Array(4), Array(4)]
Object.entries
Object.entries() 方法返回一个给定对象自身可遍历属性 [key,value] 的数组;
console.log(Object.entries(company)); // [Array(2), Array(2), Array(2)]
Object.entries 返回一个包含3个数组的数组;
这个,又可以创建一个 Map;
// 用这个结果,生成一个 map
const m = new Map(Object.entries(company));
console.log(m);
console.log(m.get('brand')); // yinsui
console.log(m.get('cities')); // ['Urumchi', 'ningbo', 'hangzhi', 'zhoushan']
Object.getOwnPropertyDescriptors
该方法返回指定对象所有自身属性的描述对象;
// 对象属性的描述对象
console.log(Object.getOwnPropertyDescriptors(company));
// 如下面这个用 Object.create 创建的对象,就有一堆描述对象
const obj = Object.create(null,{
name:{
// 设置值
value:'yinsui',
// 属性特性
writable:true,
configurable:true,
enumerable:true
}
});
可以对对象进行深层克隆;