How to check if all of items are undefined or empty string ''?
var items = [variable_1, variable_2, variable_3];
Is there any nice way to do that instead of big if? Not ES6.
You can use every:
The
every()method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.
A one liner that uses Array.prototype.some to find at least one element which is not undefined or '', if it finds one it returns true
!items.some(item => item != undefined || item != '')
!==. Also, arrow functions are ES6. OP doesn't want ES6
.every()method on the Array prototype. (edited)items.every(function(item) { return item === undefined || item === '' })is ES5.1 -- or you could just check for falsey-ness (which includes null, empty strings, undefined, etc)!item.every..allis not standard JS, it's probably some library you've used.every()or.filter()depending on what you want to do (test all values or only get the values that have some value you care about).