6个JavaScript技巧
1.检查对象是否存在属性
const person = {
name:'zhangsan',
age:18
}
console.log('name' in person) //true
console.log('job' in person) //false
2. 动态key析构对象
const person = {id:'12',name:'zhangsan'}
const {name : newName } = person
console.log('newName',newName) // newName zhangsan
const key = 'name'
const {[key] : data} = person
console.log('data',data) // data zhangsan
3.循环访问对象
const person = {id:1,name:'zhang
6个JavaScript技巧最先出现在Python成神之路。
共有 0 条评论