Is it possible to check if all variables are different from each other in another way than this?
var a = 1, b = 2, c = 3, d = 4;
if(a != b && a != c && a != d && b != a && b != c && b != d && c != a && c != b && c != d && d != a && d != b && d != c){
//All numbers are different
}
for example
if(a != b != c != d){
}
You can store them all in an object and check if the number of keys is equal to the number of variables used, like this
var dummy = {};
dummy[a] = true;
dummy[b] = true;
dummy[c] = true;
dummy[d] = true;
console.log(Object.keys(dummy).length === 4);
If the values are different, then a new key will be created every time and the number of keys will be equal to the number of variables used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With