How to change all object values in JavaScript

1 Answer

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

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

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

 



answered Apr 25, 2022 by avibootz

Related questions

1 answer 140 views
1 answer 132 views
1 answer 152 views
1 answer 108 views
1 answer 113 views
1 answer 106 views
...