Return to Snippet

Revision: 56206
at March 15, 2012 20:28 by davidwaterston


Updated Code
if (typeof String.prototype.startsWith != 'function') {
	String.prototype.startsWith = function(str) {
    	return (this.lastIndexOf(str, 0) === 0);
	};
}

Revision: 56205
at March 15, 2012 20:24 by davidwaterston


Initial Code
if (typeof String.prototype.startsWith != 'function') {
	String.prototype.startsWith = function(str) {
    	return (this.lastIndexOf(str, 0) === 0);
	};
}  

Initial URL


Initial Description
A simple Javascript function to tell if one string starts with another.

Usage:

if (myString.startsWith("anything") {
    do something…
}


NOTE: As always, make sure this is defined before it is used!

Initial Title
Case-sensitive \'Starts With\'

Initial Tags


Initial Language
JavaScript