How to increment a value in an object with JavaScript

1 Answer

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

 



answered May 11, 2022 by avibootz

Related questions

...