Skip to content

Instantly share code, notes, and snippets.

@NoMan2000
Created April 22, 2015 01:31
Show Gist options
  • Save NoMan2000/c4a0f8b0f9b027354eb1 to your computer and use it in GitHub Desktop.
Save NoMan2000/c4a0f8b0f9b027354eb1 to your computer and use it in GitHub Desktop.
Convert from -1 to 0 with ~
Works in javascript or PHP.
var foo = "foo";
if (~foo.indexOf("f")) {
console.log(~foo.indexOf("f"));
console.log("Found it!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment