Object.assign
<script>
var obj1 = { id: 1 }
var obj2 = { name: '小明' }
var o = {}
o = Object.assign(obj1, obj2)
console.log('将几个对象合并成一个对象', o); //{id: 1, name: '小明'}
</script>
Object.keys
<script>
const obj3 = { a: 1, b: 2, c: 3 }
const w = Object.keys(obj3)
console.log('返回该对象的所有属性(一个数组)', w); //['a','b','c']
</script>
Object.values
<script>
const obj3 = { a: 1, b: 2, c: 3 }
const e = Object.values(obj3)
console.log('返回该对象的所有属性值(一个数组)', e); //[1, 2, 3]
</script>
Object.freeze
<script>
const q = Object.freeze({
code: '1'
})
q.num = 999
console.log('被冻结的对象,冻结后不可新增删除修改,原型也不能被修改', q);
//{code: '1'}
</script>
JSON.parse(JSON.stringify())
<script>
const obj3 = { a: 1, b: 2, c: 3 }
const r = JSON.parse(JSON.stringify(obj3))
console.log('深拷贝', r); //{a: 1, b: 2, c: 3}
</script>
Object.entries
<script>
const obj3 = { a: 1, b: 2, c: 3 }
const d =Object.entries(obj3)
console.log('遍历对象的key与value返回二维数组',d);
//[['a', 1],['b', 2],['c', 3]]
</script>
Object.hasOwnProperty
<script>
const obj3 = { a: 1, b: 2, c: 3 }
const c = obj3.hasOwnProperty('d')
console.log('检测一个对象中是否存在某个属性,存在true不存在false',c); //false
</script>
Object.fromEntries
<script>
const arr1 = [['a', 1], ['b', 2], ['c', 3]]
const g = Object.fromEntries(arr1)
console.log('把键值对列表转换为一个对象,这个方法是和 Object.entries() 相对',g);
//{a: 1, b: 2, c: 3}
</script>
注:本人前端小白 ,如有不对的地方还请多多指教