I am getting an array undefined error in QML and am wondering what will fix this error. Here is the current code:
opacity: mBitField[index]
every once and a while it will say cannot assign undefined
to opacity
and I am wondering if this fix is valid:
opacity: mBitField[index] == "undefined" ? 0 : mBitField[index]
Basically what I am trying to say is if the array is undefined it's ok to assign a 0 opacity
otherwise assign whats in the array.
Your code converts the array element to a string which is not necessary. To check for undefined only it would be:
opacity: mBitField[index] === undefined ? 0 : mBitField[index]
Or if distinguishing undefined and null (and false, 0 or "") is not important, just use the power of Javascript :)
opacity: mBitField[index] || 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With