JSFiddle - React, Tailwind, and code Playground
by tonyleeper
HTML
<div id="console"></div>
CSS
#console {
height: 400px;
background-color: black;
color: white;
}
JavaScript
/**
{string}.startsWith() extension method
*/
var log = function (value) {
document.getElementById("console").innerHTML += value + "<br />";
};
if (typeof String.prototype.startsWith !== 'function') {
String.prototype.startsWith = function (value) {
if (value.length > this.length) {
return false;
}
for (var i = 0; i < value.length; i++) {
if (this.charAt(i) !== value.charAt(i)) {
return false;
}
}
return true;
};
}
var message = new String("Hello world!");
log(message);
log(message.startsWith("Goodbye"));
log(message.startsWith("Hello"));