1 删除一个对象的key值 2 方法1: 3 var data={ 4 province:'', 5 city:'' 6 } 7 delete(data["province"]); 8 console.log(data)//data={city:''} 9 方法2: 10 var data={ 11 province:'', 12 city:'' 13 } 14 delete data.province 15 console.log(data)//data={city:''}
1 判断对象是否存在 2 1、JSON.stringify(要判断的对象)==="{}" h5 3 2、Object.keys(要判断的对象).length===0 h5 ES6的新方法 4 3、var keys=[] 5 for(var key in {要判断的对象}){ 6 keys.push(key) 7 } 8 keys = =[] ?? 9 var keys=[] 10 for(var key in {a:1,d:2}){ 11 keys.push(key) 12 } 13 keys = =["a","b"] 14 4、jquery的isEmptyObject方法 15 var data = {} 16 var b = $.isEmptyObject(data); 17 alert(b);//true 18 5、Object.getOwnPropertyNames()方法 19 var data ={}; 20 var arr = Object.getOwnPropertyNames(data); 21 alert(arr.length==0);//true 不兼容IE8