-2

I want to increase object value just like loop i++ , but in object didnt worked , how to increase this value ? any methods?

const object = {
price:30
}

console.log(object.price++);
AlbenCFC
  • 1
  • 1

1 Answers1

0

using ++ like that is the post-increment operator meaning object.price++ returns object.price first then increments. You want the pre-increment operator ++object.price.

const object = {
  price:30
}

console.log(++object.price);
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445