首页 > 编程知识 正文

js清空对象内容,js删除对象中的某个属性

时间:2023-05-05 07:39:31 阅读:147402 作者:1652

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

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。