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

1 answer 215 views
1 answer 190 views
1 answer 218 views
1 answer 188 views
1 answer 189 views
...