本文最后更新于 2024-12-16T16:00:28+08:00
- Object.assign(obj, obj1) \(\Rightarrow\)
合并两个对象为一个==(此方法为浅拷贝)==
1 2 3 4 5 6 7 8 9 10 11
| const dealObj = (val) => { const obj = { name: "苏小妍", age: 13 }; let obj1 = { sex: "女" }; obj1 = Object.assign(obj, obj1); console.log("obj=====>>>", obj); console.log("obj1=====>>>", obj1); };
dealObj();
|
这是图片
- Object.hasOwnProperty() \(\Rightarrow\) 判断对象是否包含某个 key
1 2 3 4 5 6 7 8 9 10 11
| const hasOwnPropertyObj = (val) => { const obj = { name: "苏小妍", age: 13, sex: "女", job: "student" }; console.log("hasOwnProperty=====>>>", obj.hasOwnProperty(val)); };
hasOwnPropertyObj("name");
hasOwnPropertyObj("sex");
hasOwnPropertyObj("work");
|

- Object.keys() \(\Rightarrow\)
获取对象的所有 key
1 2 3 4 5 6 7
| const objectKeys = () => { const obj = { name: "苏小妍", age: 13, sex: "女", job: "student" }; console.log("objectKeys=====>>>", Object.keys(obj)); };
objectKeys();
|

- Object.values() \(\Rightarrow\)
获取对象的所有 value
1 2 3 4 5 6
| const objectValues = () => { const obj = { name: "苏小妍", age: 13, sex: "女", job: "student" }; console.log("objectValues=====>>>", Object.values(obj)); }; objectValues();
|

- Object.entries() \(\Rightarrow\)
获取对象的所有 key 和所有 value
1 2 3 4 5 6 7 8 9
| const objectEntries = () => { const obj = { name: "苏小妍", age: 13, sex: "女", job: "student" }; console.log("objectEntries=====>>>", Object.entries(obj)); }; objectEntries();
|

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| const fruitsArr = [ "Banana", "Cherry", "Peach", "Kiwi", "Leamon", "Watermelon", "Strawberry", "Orange", "Apple", "Mango", "Banana", ];
Object.prototype.toString.call(fruitsArr.join("-")); Object.prototype.toString.call(fruitsArr);
|
js之Object的使用
https://www.gongyibai.site/Object/