Object知道不知道
assign
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| let obj1 = { a: 111, b: { c: 123 } } let obj2 = { c: 111, b: { e: 123 } }
let ret = Object.assign(obj1, obj2) console.log(ret)
|
1 2 3 4 5 6
| { a: 111, b: { e: 123 } }
|
create
1 2 3 4 5 6 7 8 9 10
| const obj = { name: 'limo', print() { console.log(`name:${this.name}`) } }
const newObj = Object.create(obj) newObj.name = 'jack' newObj.print()
|
entries
1 2 3 4 5 6 7 8 9 10 11 12 13
| const object1 = { a: 'somestring', b: 42 };
for (let [key, value] of Object.entries(object1)) { console.log(`${key}: ${value}`); }
|
keys
1 2 3 4
| var obj = { 0: 'a', 1: 'b', 2: 'c' }; console.log(Object.keys(obj));
|
values
1 2
| var obj = { 0: 'a', 1: 'b', 2: 'c' }; console.log(Object.values(obj));
|
fromEntries
1 2 3 4 5 6 7 8 9
| const entries = new Map([ ['foo', 'bar'], ['baz', 42] ]);
const obj = Object.fromEntries(entries);
console.log(obj);
|
is
判断两个是否相同的成立方式
- 两个值都是 undefined
- 两个值都是 null
- 两个值都是 true 或者都是 false
- 两个值是由相同个数的字符按照相同的顺序组成的字符串
- 两个值指向同一个对象
- 两个值都是数字并且
- 都是正零 +0
- 都是负零 -0
- 都是 NaN
- 都是除零和 NaN 外的其它同一个数字