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 150 views
1 answer 142 views
1 answer 163 views
1 answer 122 views
1 answer 129 views
1 answer 120 views
...