JS如何将对象的属性var obj={name: 'zhagnsan ',age :19 } deletete obj.name//truetypeofobj.name//undefined转换为dele
可以删除其他东西吗? 1 .变量var name='zs' //声明的变量delete name//false console.log (type of name )//Stringage=19 //未声明的变量deleteage ) window下的变量delete this.val//true console.log (type of this.val )//undefined声明的变量windows
2 .函数varfn=function{}/声明的函数delete fn//false console.log (type off n )//functionfn=function ) }/未声明的函数DDN '3'] ///声明的数组delete arr//false console.log (arr类型)/objectarr=[''] '3'//未声明的数组delete arr//true '2','3']/声明的数组deletearr '3'] 4.对象var person={ height: 180,long: 180,weight: 180,hobby 3360 { baby music 3360 ' nice ' } delete person//false console.log (type of person )/objectvar person=(height 3360180,long 330 hoby 330 ) music : ' nice ' } delete person.hobby//true console.log (type of person.hobby