How to reduce this syntax in a matrix props field?

Hi,

In the props field of a matrix... is there another way to code this ?

This works well :

props.colorStroke = $ === 0 || $ == 6 || $ == 12... || $ == 60 ? 'white' : 'red'

so i tried to use this, and that's ok...

var Index = $ === 0 || $ == 6 || $ == 12 ... || $ == 60 ...

But i need more entries... and i would like stg like :

var Index = [0,6,12,33...]
for(var i = 0; ... ; i++) {props.colorStroke = $ == Index[i] ? 'white' : 'red'}

And there, only the last index is considered...

So...

Thank you

Hi Sylvian,

If you have many entries in an array, you can use .includes() array method to check if a single value is in that array, like so:

const indexes = [0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60]
props.colorStroke = indexes.includes($) ? 'white' : 'red'

Hope it helps :slight_smile:

Oh, yep, it helps :+1: thank you very much ! What drives me crazy is that i had this '.includes' in mind... I'm still so confused with "how to code into this part... into this one..." , you saved my week :smiley:

1 Like

Array is a powerfull tool. This can help you a lot Array - JavaScript | MDN

:slight_smile: yep, i've just spent hours on those pages :upside_down_face: Now need to integrate (?) all this !

This page helps you to be aware of the possibilities but yes use them is another story, journey depending yours needs.
Good luck

Thank you :wink: