How to change all object values in TypeScript

1 Answer

0 votes
const obj = {
  id: 383912,
  name: "Albus Dumbledore",
  academicrank: "Professor"
};

Object.keys(obj).forEach((key, index) => {
  	obj[key] = obj[key] + '-' + index + 'X';
});

console.log(obj);
   
   
   
   
/*
run:
   
{
  id: '383912-0X',
  name: 'Albus Dumbledore-1X',
  academicrank: 'Professor-2X'
}
   
*/

 



answered Apr 25, 2022 by avibootz
...