I'm trying to show a warning to the user. I have an array that I split, and I always use the values in positions 0 and 1. Occasionally, there might be a value in position 2, but not always.
I want to create a message string that displays the value of arr[2] if it exists, or just arr[0] and arr[1] if arr[2] is not present.
I attempted to do it like this:
strWarningMsg =
arr[2].length > 0 ? arr[1] + arr[2] + ' meeting, ' + '\nscheduled for: ' + arr[0].replace(/ +/g, " ")
+ '; data has been already uploaded.\n' + '\n Changes to the existing data could potentially invalidate any existing registration(s). Make sure to use the Cross-Reference file template before you attempt a new upload for this meeting.'
+ '\n\nPress OK to overwrite the existing Cross Reference List, or\nPress Cancel to abort the operation.'
: arr[1] + ' meeting, ' + '\nscheduled for: ' + arr[0].replace(/ +/g, " ")
+ '; data has been already uploaded.\n' + '\n Changes to the existing data could potentially invalidate any existing registration(s). Make sure to use the Cross-Reference file template before you attempt a new upload for this meeting.'
+ '\n\nPress OK to overwrite the existing Cross Reference List, or\nPress Cancel to abort the operation.';
While I can see the redundancy in the code, I know it's not the best practice. It seems to work fine when arr[2] has a value, but it breaks when arr[2] is not there. Can someone show me the correct way to use the ternary operator to get this right?
Thanks, Erasmo.