js清空对象和对象的值:


js清空对象:

var obj={'a':1,'b':2}

     for(let key in obj){

         delete obj[key]

     }

console.log(obj)  //{}

js清空对象的值:

var obj={'a':1,'b':2}

     for(let key in obj){

         obj[key]  = ''

     }

console.log(obj)   //{'a':'','b':''}

let person={name:'kobe',gender:'男'}

Object.keys(person).forEach(key => (person[key] = ''));

你可能感兴趣的:(实战,javascript,前端,开发语言)