startsWith

This article is in need of a technical review.

This article is in need of an editorial review.

  • Tags
  • Files

Introduced in JavaScript 1.8.6

Determines whether a string begins with the characters of another string, returning true or false as appropriate.

Method of String
Implemented in JavaScript 1.8.6
ECMAScript Edition None (Harmony Proposal)

Syntax

var startsWith = str.startsWith(searchString [, position]);

Parameters

searchString
The characters to be searched for at the start of this string.
position
The position in this string at which to begin searching for searchString; defaults to 0.

Description

This method lets you determine whether or not a string begins with another string.

Examples

var str = "To be, or not to be, that is the question.";

print(str.startsWith("To be"));         // true
print(str.startsWith("not to be"));     // false
print(str.startsWith("not to be", 10)); // true
Contributors to this page: ethertank, Waldo, dbruant
Last updated by: ethertank,
Last reviewed by: ethertank,