Skip to content

Instantly share code, notes, and snippets.

@valeriu
Last active December 14, 2015 21:39
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 valeriu/5152614 to your computer and use it in GitHub Desktop.
Save valeriu/5152614 to your computer and use it in GitHub Desktop.
Reports the zero-based index position of the last occurrence of a specified Unicode character or string within this instance. The method returns -1 if the character or string is not found in this instance.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>lastIndexOf</title>
</head>
<body>
<script type="text/javascript">
var str = "abcdefabcdef"
document.write(str.lastIndexOf('a')+"<br />");
//abcdefabcdef (string)
// × (finded)
// × (start) <--
document.write(str.lastIndexOf('a',2)+"<br />");
//abcdefabcdef (string)
//× (finded)
// × (start) <--
document.write(str.lastIndexOf('a',10)+"<br />");
//abcdefabcdef (string)
// × (finded)
// × (start) <--
document.write(str.lastIndexOf('a',0)+"<br />");
//abcdefabcdef (string)
//× (finded)
//× (start) <--
document.write(str.lastIndexOf('C',0)+"<br />");
//abcdefabcdef (string)
// (not found)
// × (start) <--
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment