How to increment a value in an object with TypeScript

1 Answer

0 votes
const obj = {
  typescript: 1,
  c: 99,
  python: 88,
};
  
obj.typescript = obj.typescript + 1 || 1;
  
console.log(obj);
     
     
     
     
/*
run:
     
 {
  "typescript": 2,
  "c": 99,
  "python": 88
} 
     
*/

 



answered May 11, 2022 by avibootz

Related questions

1 answer 153 views
1 answer 102 views
1 answer 125 views
1 answer 119 views
1 answer 161 views
...