How to set all values in an object to null using JavaScript

1 Answer

0 votes
const obj = {
  name: 'Ben',
  age: 40,
  workin: 'JavaScript',
};

Object.keys(obj).forEach(key => {
  	obj[key] = null;
});

console.log(obj);

  
  
  
  
/*
run:
  
{
  age: null,
  name: null,
  workin: null
}
  
*/

 



answered May 13, 2022 by avibootz

Related questions

...