Skip to content

Instantly share code, notes, and snippets.

@yannbertrand
Created January 18, 2016 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yannbertrand/d40936f1e2af06a3fb96 to your computer and use it in GitHub Desktop.
Save yannbertrand/d40936f1e2af06a3fb96 to your computer and use it in GitHub Desktop.
Simplify the use of indexOf
// Array
var list = ['my', 'str', 'list'];
if (~list.indexOf('my')) {
console.log('the `list` array contains \'my\'');
}
if (!~list.indexOf('number')) {
console.log('the `list` array does not contain \'number\'');
}
// String
var hello = 'world';
if (~hello.indexOf('orl')) {
console.log('`hello` contains \'orl\'');
}
if (!~hello.indexOf('qsd')) {
console.log('`hello` does not contain \'qsd\'');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment