SQL:
something in ('X','Y','Z','0')
Modern JavaScript (including IE>8):
['X','Y','Z','0'].indexOf(something)>-1
More Modern JavaScript (!IE):
['X','Y','Z','0'].includes(something)
If you need a simple includes polyfill for legacy browsers (including IE):
if(!Array.prototype.includes) Array.prototype.includes =function(value,start) {
start=parseInt(start)||0;
for(var i=start;i<this.length;i++) if(this[i]==value) return true;
return false;
};
In deference to AuxTaco’s comment, here is a version of the polyfill which works for IE>8:
if (!Array.prototype.includes) Object.defineProperty(Array.prototype, 'includes', {
value: function(value,start) {
start=parseInt(start)||0;
for(var i=start;i<this.length;i++) if(this[i]==value) return true;
return false;
}
});
inoperator in javascript. I am not sure if the ones you want to achieve can be done with this developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/…inin JavaScript is used to test whether a property exists in an Object. Things are further complicated by the fact that JavaScript arrays are actually specialised objects, so usinginwith an array is valid, but probably not what you have in mind. It tests whether something is a valid property of the array object, but not whether it is an existing value in the array itself.