From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- .../global_objects/string/endswith/index.html | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 files/pt-br/web/javascript/reference/global_objects/string/endswith/index.html (limited to 'files/pt-br/web/javascript/reference/global_objects/string/endswith') diff --git a/files/pt-br/web/javascript/reference/global_objects/string/endswith/index.html b/files/pt-br/web/javascript/reference/global_objects/string/endswith/index.html new file mode 100644 index 0000000000..0e62545d41 --- /dev/null +++ b/files/pt-br/web/javascript/reference/global_objects/string/endswith/index.html @@ -0,0 +1,103 @@ +--- +title: String.prototype.endsWith() +slug: Web/JavaScript/Reference/Global_Objects/String/endsWith +tags: + - JavaScript + - Prototipo + - Referencia + - String + - endsWith() + - metodo +translation_of: Web/JavaScript/Reference/Global_Objects/String/endsWith +--- +
{{JSRef}}
+ +
+ +

O método endsWith() indica se uma string termina com determinados caracteres, retornando true ou false.

+ +

Sintaxe

+ +
str.endsWith(stringSendoBuscada[, tamanho])
+ +

Parâmetros

+ +
+
stringSendoBuscada
+
Os caracteres a serem pesquisados no final da string.
+
tamanho
+
Opcional. Se fornecido, substitui o tamanho da string passada. Se omitido, o valor padrão é o tamanho da string.
+
+ +

Valor retornado

+ +

true se os caracteres passados forem encontrados no final da string. Do contrário, retorna false.

+ +

Descrição

+ +

Este método permite que você verifique se uma string termina ou não com determinados caracteres. Este método é case-sensitive.

+ +

Exemplos

+ +

Usando endsWith()

+ +
var str = 'Ser ou não ser, eis a questão';
+
+console.log(str.endsWith('questão')); // retorna true
+console.log(str.endsWith('ser'));     // retorna false
+console.log(str.endsWith('ser', 14)); // retorna true
+
+ +

Polyfill

+ +

Este método foi adicionada na especificação ECMAScript 6 e talvez não esteja disponível em todos as implementações JavaScript ainda. No entanto, você pode criá-lo adicionando o seguinte código:

+ +
if (!String.prototype.endsWith)
+  String.prototype.endsWith = function(searchStr, Position) {
+      // This works much better than >= because
+      // it compensates for NaN:
+      if (!(Position < this.length))
+        Position = this.length;
+      else
+        Position |= 0; // round position
+      return this.substr(Position - searchStr.length,
+                         searchStr.length) === searchStr;
+  };
+
+ +

Especificações

+ + + + + + + + + + + + + + + + + + + +
EspecificaçãoStatusComentário
{{SpecName('ES6', '#sec-string.prototype.endswith', 'String.prototype.endsWith')}}{{Spec2('ES6')}}Definição inicial.
{{SpecName('ESDraft', '#sec-string.prototype.endswith', 'String.prototype.endsWith')}}{{Spec2('ESDraft')}}
+ + + + + +

{{Compat("javascript.builtins.String.endsWith")}}

+ +

Veja também

+ + -- cgit v1.2.3-54-g00ecf