数组扩展方法
Object.assign()
对象浅拷贝。
javascript
const obj = {
name: 'xiaoming',
age: 18
}
const obj2 = Object.assign({}, obj)
obj2.name = 'libai'
console.log(obj.name) // 'xiaoming'
const obj = {
name: 'xiaoming',
age: 18
}
const obj2 = Object.assign({}, obj)
obj2.name = 'libai'
console.log(obj.name) // 'xiaoming'
Object.keys()
提取对象的所有键组成一个数组返回。
javascript
const obj = {
name: 'xiaoming',
age: 18
}
const keys = Object.keys(obj) // ['name', 'age']
const obj = {
name: 'xiaoming',
age: 18
}
const keys = Object.keys(obj) // ['name', 'age']
Object.values()
提取对象的所有值组成一个数组返回。
javascript
const obj = {
name: 'xiaoming',
age: 18
}
const values = Object.values(obj) // ['xiaoming', 18]
const obj = {
name: 'xiaoming',
age: 18
}
const values = Object.values(obj) // ['xiaoming', 18]