Reputation: 335
Is there a syntactical way to shorten a long if conditional like in the example below
if (invoice.get('status') !== 'claimed' && invoice.get('status') !== 'paid' && invoice.get('status') !== 'cancelled' )
to
if (invoice.get('status') !== 'claimed' && 'paid' && 'cancelled' )
or something like
if (invoice.get('status') !== 'claimed', 'paid', 'cancelled' )
Upvotes: 1
Views: 38
Reputation: 8239
You can shorten it by using an Array of status:
if (!['claimed', 'paid', 'cancelled'].includes(invoice.get('status')))
Upvotes: 1
Reputation: 386624
You could take an array with the not wanted values and check with Array#includes
.
if (!['claimed', 'paid', 'cancelled'].includes(invoice.get('status')) {
Upvotes: 4
Reputation: 1105
if(!['claimed', 'paid', 'cancelled'].includes(invoice.get('status'))
Upvotes: 1