Hi! Is there any way to get the total number of values in a switch prop? I want to use it for CSS n-selectors in a JS{{}} loop without having to manually write out a lot of n-selectors.
Yes you can use getProp()
combined with Object.keys()
, like so:
const switchLen = Object.keys(getProp("switch_id", "values")).length
This would work in a script property such as onValue
@ClelsonLopes, but to do that in a JS{} block in a normal property you need to use the @{} syntax instead of getProp()
:
JS{
var n = Object.keys(@{switch_id.values}).length
// do something with n ?
}
1 Like
You are so on it it's not even funny