DEV Community

Discussion on: A neat little trick with JavaScript's indexOf()

Collapse
 
ijlee2 profile image
Isaac Lee

Unless one will reuse the index in other places, I like to recommend includes instead of indexOf. I think it's more readable.


if (arr.includes('foo')) { ... }

Collapse
 
thehanna profile image
Brian Hanna

Lack of IE support is a huge bummer since I still have to support IE11 for all my work projects, but that's definitely more readable

Collapse
 
ijlee2 profile image
Isaac Lee

Indeed, Brian. I have to support IE11 too. I believe the polyfill solution that others have mentioned here would help.

Cheers,