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

1 Answer

0 votes
const obj = {
  name: 'Tim',
  age: 50,
  workin: 'TypeScript',
};

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

console.log(obj);

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

 



answered May 13, 2022 by avibootz

Related questions

...