1611 shaares
17 private links
17 private links
5 results
tagged
es6
const result = _.map({a: 1, b: 2}, function(value, key) {
return value + key;
});
Since nobody has added the obvious solution yet which works fine for two comparisons, I'll offer it:
if (foobar == foo || foobar == bar) {
//do something
}
And, if you have lots of values, then I'd suggest making a Set as this makes very clean and simple comparison code and it's fast at runtime:
// pre-construct the Set
var tSet = new Set([foo, bar, test1, test2, test3]);
// test the Set at runtime
if (tSet.has(foobar)) {
// do something
}
For pre-ES6, you can get a Set polyfill of which there are many. One is described in this other answer.
A quick overview of new JavaScript features in ES2015, ES2016, ES2017 and beyond.