Is it possible to put an if statement within an Array Declaration?
Code:
dayOfWeek = [if($('#sunday').checked()){$('#sunday').val()}];
Browser error: Uncaught SyntaxError: Unexpected token if.
I tried too:
$('#domingo').checked() ! $('#domingo').val() : 0
Browser error: Uncaught SyntaxError: Unexpected token !
EDIT
As @bažmegakapa answered the code that works with no error is:
diasSemana = new Array($domi.is(':checked') ? $domi.val() : null, $lun.is(':checked') ? $lun.val() : null);
This did not work:
$('#domingo').checked() ? $('#domingo').val() : 0
Browser showed this error: Uncaught TypeError: Object [object Object] has no method 'checked'
Regards!
[]instead ofnew Array().