ES6 Set.has() vs. Array.indexOf()

I decided to use the new ES6 Set.has() language construct instead of Array.indexOf(). Turns out they’re the same character length.

if (new Set(Object.keys(commands)).has(process.argv[2])) {

…vs.

if (Object.keys(commands).indexOf(process.argv[2] > -1)) {

I’m sticking with Set. It works, the code is clean and it kind of reminds me of Python. The indexOf check feels more fragile since it’s easy to lose the actual condition at the end there.

Leave a comment