['', ''] == ['', '']
returns false
because in JavaScript arrays are objects, and objects in JavaScript have reference semantics. Comparing objects to each other actually compares their reference IDs, which will be different for different references. So, even though both sides of ==
are the "same" array, they are different references.
If you want to check that an array only contains empty strings, use Array.prototype.every
as in the following:
myArray = ['']
console.log(myArray.every(el => el === '')) // true
myArray = []
console.log(myArray.every(el => el === '')) // true
myArray = ['test']
console.log(myArray.every(el => el === '')) // false
If you are in an environment without ES6 support, you can swap the el => el === ''
for function(el) { return el === '' }
.