JS: String.prototype.startsWith

By Xah Lee. Date: . Last updated: .

New in JS2015.

str.startsWith(searchString)
  • Return true if str starts with searchString.
  • Else, return false.
console.log("abcd".startsWith("ab"));
console.log("abcd".startsWith("b") === false);
str.startsWith(searchString, position)

Check if start from position.

console.log("abcd".startsWith("b", 1));

JS String.prototype