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/startswith/index.html | 128 +++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 files/ca/web/javascript/reference/global_objects/string/startswith/index.html (limited to 'files/ca/web/javascript/reference/global_objects/string/startswith') diff --git a/files/ca/web/javascript/reference/global_objects/string/startswith/index.html b/files/ca/web/javascript/reference/global_objects/string/startswith/index.html new file mode 100644 index 0000000000..ca25398d51 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/string/startswith/index.html @@ -0,0 +1,128 @@ +--- +title: String.prototype.startsWith() +slug: Web/JavaScript/Referencia/Objectes_globals/String/startsWith +translation_of: Web/JavaScript/Reference/Global_Objects/String/startsWith +--- +
{{JSRef}}
+ +

El mètode startsWith() determina si un string comença amb els caràcters d'un altre string, retornant true o false depenent d'això.

+ +

Sintaxi

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

Paràmetres

+ +
+
stringAcercar
+
Els caràcters a cercar al començament d'aquest string.
+
posició
+
Opcional. La posició dins el string a la qual es començarà a cercar per a trobar stringAcercar; per defecte és 0.
+
+ +

Descripció

+ +

Aquest mètode us permet determinar si un string comença amb un altre string.

+ +

Exemples

+ +

Utilitzar startsWith()

+ +
var str = 'To be, or not to be, that is the question.';
+
+console.log(str.startsWith('To be'));         // true
+console.log(str.startsWith('not to be'));     // false
+console.log(str.startsWith('not to be', 10)); // 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.startsWith():

+ +
if (!String.prototype.startsWith) {
+  String.prototype.startsWith = function(searchString, position) {
+    position = position || 0;
+    return this.indexOf(searchString, position) === position;
+  };
+}
+
+ +

Trobareu una funció Polyfill més robusta i optimitzada al GitHub de Mathias Bynens.

+ +

Especificacions

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

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatChrome("41")}}{{CompatGeckoDesktop("17")}}{{CompatNo}}{{CompatChrome("41")}}{{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