steveosoule
5/15/2013 - 10:13 PM

javascript-string-starts-with.js

javascript-string-starts-with.js

if (typeof String.prototype.startsWith != 'function') {
  // see below for better implementation!
  String.prototype.startsWith = function (str){
    return this.indexOf(str) == 0;
  };
}

"Hello World!".startsWith("He"); // true

var data = "Hello world";
var input = 'He';
data.startsWith(input); // true