[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith [Back]  [Original]

String.prototype.startsWith() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

String.prototype.startsWith()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..

startsWith() , , , , true false.

In this article

str.startsWith(searchString[, position])

searchString

, .

position

. , searchString; 0.

, .

: startsWith()

js
var str = "   ,    .";

console.log(str.startsWith("")); // true
console.log(str.startsWith(" ")); // false
console.log(str.startsWith(" ", 9)); // true

ECMAScript 6 JavaScript. , :

js
if (!String.prototype.startsWith) {
  Object.defineProperty(String.prototype, "startsWith", {
    enumerable: false,
    configurable: false,
    writable: false,
    value: function (searchString, position) {
      position = position || 0;
      return this.indexOf(searchString, position) === position;
    },
  });
}


Web Proxy Viewer  |  New URL  |  Original Page