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

String.prototype.endsWith() - 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.endsWith()

Baseline Widely available

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

endsWith() , , , , true false.

In this article

str.endsWith(searchString[, length])

searchString

, .

length

. , ; .

true ; , false.

, . .

: endsWith()

js
var str = "   ,    .";

console.log(str.endsWith(".")); // true
console.log(str.endsWith("")); // false
console.log(str.endsWith("", 16)); // true

ECMAScript 6 JavaScript. , :

js
if (!String.prototype.endsWith) {
  Object.defineProperty(String.prototype, "endsWith", {
    value: function (searchString, position) {
      var subjectString = this.toString();
      if (position === undefined || position > subjectString.length) {
        position = subjectString.length;
      }
      position -= searchString.length;
      var lastIndex = subjectString.indexOf(searchString, position);
      return lastIndex !== -1 && lastIndex === position;
    },
  });
}

Specification
ECMAScript 2027 LanguageSpecification
# sec-string.prototype.endswith


Web Proxy Viewer  |  New URL  |  Original Page