与前俩篇博客相对应,该篇继续介绍Object(对象)的常用API。
四、Object.getOwnPropertyDescriptor( obj, prop )
获取obj这个对象的prop属性的属性描述符(property descriptor)
example如下:
var obj = {
x: 1
}
console.log( Object.getOwnPropertyDescriptor( obj,"x" ) );
//{ value: 1, writable: true, enumerable: true, configurable: true}
五、ES8新增的Object的方法
(一)Object.entries( obj )
获取obj这个对象的键名和键值,且以二维数组的形式输出
example如下:
var obj = {
x: 1,
y:2
}
console.log( Object.entries( obj ) );
//[[x,1