1

I have an object that comes like this:

let sizes = {
'30': false,
'36': false,
'40': false
}

I was wandering is it possible to toggle all of them with one function, so that only one value is true at a time, while not depending on the key and the length of the object?

It seems that For-in loop would be great for that, I'm just not sure how to approach it.

I've been sitting on this problem for a couple of hours, and cannot seem to find something similar. Thank you!

Raman S.
  • 25
  • 7
  • 1
    What will determine which value should be the only true value? – Calvin Nunes Jan 20 '20 at 19:31
  • 1
    That's invalid syntax. Numbers as object keys must be quoted. You also need commas separating the attributes . – Rick Hitchcock Jan 20 '20 at 19:33
  • A [comment on the accepted answer](https://stackoverflow.com/questions/40836239/set-all-object-keys-to-false#comment68890364_40836350) to the duplicate question addresses the issue of one property remaining `true`. – isherwood Jan 20 '20 at 19:35
  • 1
    Why this question is close ? the question was how to toggle not how to set all key to false. – ZecKa Jan 20 '20 at 20:29

0 Answers0