1、Object.values 返回一个给定对象自身的所有可枚举属性值的数组
2、Object.entries 返回一个数组,其元素是与直接在object上找到的可枚举属性键值对相对应的数组。
3、Object.getOwnPropertyDescriptors 返回对象属性的描述对象
let json = {
name:'张三',
age:12,
skill:'dance'
}
console.log(Object.values(json))
Object.entries 返回的是一个数组,数组里买呢还是一个数组,这种结构利于创建Map
![](https://img.haomeiwen.com/i19978726/73cc29b95df89544.png)
![](https://img.haomeiwen.com/i19978726/b570090978d995a6.png)
let json2 = {
friends:['朋友1','朋友2','朋友三'],
age:23,
children:['孩子1']
}
console.log(Object.entries(json2))
![](https://img.haomeiwen.com/i19978726/323f64ba308c3ed0.png)
![](https://img.haomeiwen.com/i19978726/7106d405a9e630e1.png)
Object.getOwnPropertyDescriptors
![](https://img.haomeiwen.com/i19978726/79ce878af18f52bc.png)
对象属性的描述通过Object.create设置
const b = Object.create(null,{
name:{
value:'张三',
writable:true, //是否可以重写
configurable:true,//是否可以删除
enumerable:true//是否可以枚举
}
})
console.log(Object.getOwnPropertyDescriptors(b))
![](https://img.haomeiwen.com/i19978726/bcff045dd8a49158.png)
网友评论