1.Object.entries()
Object.entries:遍历对象,把属性,值组成数组,再返回一个新的二维数组
let obj = { 'a': 1, "b": 2, "c": 3 };
let obj1 = Object.entries(obj);
输出:[["a", 1],["b", 2],["c", 3]]
let obj2 = Object.fromEntries(obj1)//{ a: 1, b: 2, c: 3 };
2.Object.fromEntries()
Object.fromEntries:把Object.entries转换后的二维数组重新转换为对象
let obj = { 'a': 1, "b": 2, "c": 3 };
let obj1 = Object.entries(obj);
let obj2 = Object.fromEntries(obj1)
输出:{ a: 1, b: 2, c: 3 };
3.Object.values()
Object.values:遍历对象,返回对象所有value值,组成数组
let obj = { 'a': 1, "b": 2, "c": 3 };
let valueArr = Object.values(obj);
输出:[1,2,3];
4.Object.keys()
Object.keys:遍历对象,返回对象所有key,组成数组
let obj = { 'a': 1, "b": 2, "c": 3 };
let keyArr = Object.keys(obj);
输出:["a", "b", "c"]
5.Object.create()
Object.create:创建对象,带着指定的原型对象和属性
let obj = { 'a': 1, "b": 2, "c": 3 };
let keyArr = Object.keys(obj);
输出:["a", "b", "c"]
6.Object.assign()
Object.assign:复制一个对象(浅拷贝)/合并对象
语法:Object.assign(对象1,对象2,对象3};
let obj = { 'a': 1, "b": 2, "c": 3 };
let objA = { name: "cao" }
let assaginObj = Object.assign({}, obj);
输出:{ a: 1, b: 2, c: 3 }
let assaginObj1 = Object.assign(obj, objA);
输出:{a: 1, b: 2, c: 3, name: "cao"}
7.Object.is()
Object.is:比较两个值是否一样,与===类似
不同的是 -0 != +0 ,NAN==NAN
Object.is(-0, +0);//false
Object.is(NaN, NaN);//true
NaN == NaN//false
- 0 == +0;//true
8.Object.getOwnPropertyDescriptor()
getOwnPropertyDescriptor:查找对象指定的属性,有就返回相应数据,没有返回undfined
let obj = { 'a': 1, "b": 2, "c": 3 };
Object.getOwnPropertyDescriptor(obj, 'a');
输出:{value: 1, writable: true, enumerable: true, configurable: true}
Object.getOwnPropertyDescriptor(obj, 'test');
输出:undfined
9.Object.getOwnPropertyDescriptors()
Object.getOwnPropertyDescriptors:返回对象的所有属性的属性描述符,没有属性返回{}
let obj = { 'a': 1, "b": 2, "c": 3 };
Object.getOwnPropertyDescriptors(obj);
输出:{
a: {value: 1, writable: true, enumerable: true, configurable: true},
b: {value: 2, writable: true, enumerable: true, configurable: true},
c: {value: 3, writable: true, enumerable: true, configurable: true},
}
Object.getOwnPropertyDescriptors({});
输出:{}
10.Object.getOwnPropertyNames()
Object.getOwnPropertyNames:遍历对象,返回对象所有key,组成数组
与Object.keys()效果一致
let obj = { 'a': 1, "b": 2, "c": 3 };
Object.getOwnPropertyNames(obj);
输出:["a", "b", "c"]
11.Object.getPrototypeOf()
Object.getPrototypeOf: 该方法返回对象的原型对象,如果没有的话,则返回null
let obj = { 'a': 1, "b": 2, "c": 3 };
Object.getPrototypeOf(obj);