Javascript handles null and null value examples
- 2020-03-30 03:19:46
- OfStack
function dealNull(obj){
for(var i in obj){
if(null == obj[i] || 'null' == obj[i]){
obj[i]='';
}else if('object' == typeof obj[i]){
dealNull(obj[i]);
}
}
};
//Test object
var a={};
a.aa=null;
a.bb='null';
a.c=1;
a.b={};
a.b.aaa=null;
a.b.bbb='null';
a.b.c=1;
a.array=[];
a.array.push({'a':null,'b':'null','c':1});
a.array.push({'a1':null,'b1':'null','c1':1});
a.array.push({'a2':null,'b2':'null','c2':1});
dealNull(a);