The .indexOf()
methods for both String and Array return numeric types. In some cases, it can be confused with the .includes()
method and used as a boolean type.
if (arr.indexOf(x)) {}
arr.indexOf(x) ? foo : bar
arr.indexOf(x) && arr.map(item => item.id)
if (arr.indexOf(x) !== -1) {}
arr.includes(x) ? foo : bar
arr.indexOf(x) + offset