Skip to content

Instantly share code, notes, and snippets.

@fal-works
Created April 26, 2020 00:11
Show Gist options
  • Save fal-works/9f880a7b3f347eccf3af8b688da5a545 to your computer and use it in GitHub Desktop.
Save fal-works/9f880a7b3f347eccf3af8b688da5a545 to your computer and use it in GitHub Desktop.
str.lastIndexOf(searchString, null) returns -1
// Node v13.12.0
const str = "abcde";
const searchString = "c";
const indices = [
str.indexOf(searchString), // 2
str.indexOf(searchString, null), // 2
str.lastIndexOf(searchString), // 2
str.lastIndexOf(searchString, null) // -1
];
indices.forEach((n, i) => console.log(`case${i}: ${n}`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment