From cb9e359a51c3249d8f5157db69d43fd413ddeda6 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:45:12 +0100 Subject: unslug ca: move --- .../global_objects/string/endswith/index.html | 133 +++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 files/ca/web/javascript/reference/global_objects/string/endswith/index.html (limited to 'files/ca/web/javascript/reference/global_objects/string/endswith') diff --git a/files/ca/web/javascript/reference/global_objects/string/endswith/index.html b/files/ca/web/javascript/reference/global_objects/string/endswith/index.html new file mode 100644 index 0000000000..83a1201549 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/string/endswith/index.html @@ -0,0 +1,133 @@ +--- +title: String.prototype.endsWith() +slug: Web/JavaScript/Referencia/Objectes_globals/String/endsWith +translation_of: Web/JavaScript/Reference/Global_Objects/String/endsWith +--- +
{{JSRef}}
+ +

El mètode endsWith() method determina si un string acaba amb els caràcters d'un altre string, retornant true o false depenent d'això.

+ +

Sintaxi

+ +
str.endsWith(stringAcercar[, posició])
+ +

Paràmetres

+ +
+
stringAcercar
+
Els caràcters a cercar al final d'aquest string.
+
posició
+
Opcional. Cerca dins aquest string considerant posició com la última posició del string; per defecte rep el valor del tamany total del string.
+
 
+
 
+
+ +

Descripció

+ +

Aquest mètode us permet determinar si un string acaba en un altre string.

+ +

Exemples

+ +

Utilitzar endsWith()

+ +
var str = 'To be, or not to be, that is the question.';
+
+console.log(str.endsWith('question.')); // true
+console.log(str.endsWith('to be'));     // false
+console.log(str.endsWith('to be', 19)); // true
+
+ +

Polyfill

+ +

Aquest mètode va ser afegit a l'especificació ECMAScript i pot no estar disponible encara a totes les implementacions de JavaScript. No obstant, la funció següent emula el comportament de String.prototype.endsWith():

+ +
if (!String.prototype.endsWith) {
+  String.prototype.endsWith = function(searchString, position) {
+      var subjectString = this.toString();
+      if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
+        position = subjectString.length;
+      }
+      position -= searchString.length;
+      var lastIndex = subjectString.indexOf(searchString, position);
+      return lastIndex !== -1 && lastIndex === position;
+  };
+}
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-string.prototype.endswith', 'String.prototype.endsWith')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatChrome("41")}}{{CompatGeckoDesktop("17")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatChrome("36")}}{{CompatGeckoMobile("17")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

Vegeu també

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