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.
str.startsWith(searchString, position)
Check if start from position.
const ss = "abcd";

console.log(ss.startsWith("ab"));
console.log(ss.startsWith("b") === false);

console.log(ss.startsWith("b", 1));
BUY ΣJS JavaScript in Depth