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 --- .../objectes_globals/string/anchor/index.html | 118 ------- .../objectes_globals/string/big/index.html | 114 ------- .../objectes_globals/string/blink/index.html | 110 ------- .../objectes_globals/string/bold/index.html | 106 ------- .../objectes_globals/string/charat/index.html | 283 ----------------- .../objectes_globals/string/concat/index.html | 125 -------- .../objectes_globals/string/endswith/index.html | 133 -------- .../objectes_globals/string/fixed/index.html | 103 ------- .../objectes_globals/string/fontcolor/index.html | 122 -------- .../objectes_globals/string/fontsize/index.html | 121 -------- .../string/fromcharcode/index.html | 126 -------- .../referencia/objectes_globals/string/index.html | 340 --------------------- .../objectes_globals/string/indexof/index.html | 190 ------------ .../objectes_globals/string/italics/index.html | 104 ------- .../objectes_globals/string/length/index.html | 121 -------- .../objectes_globals/string/link/index.html | 119 -------- .../objectes_globals/string/normalize/index.html | 154 ---------- .../objectes_globals/string/small/index.html | 110 ------- .../objectes_globals/string/startswith/index.html | 128 -------- .../objectes_globals/string/sub/index.html | 109 ------- .../objectes_globals/string/substr/index.html | 156 ---------- .../objectes_globals/string/sup/index.html | 107 ------- .../string/tolocalelowercase/index.html | 110 ------- .../string/tolocaleuppercase/index.html | 110 ------- .../objectes_globals/string/tolowercase/index.html | 111 ------- .../objectes_globals/string/tostring/index.html | 113 ------- .../objectes_globals/string/touppercase/index.html | 110 ------- .../objectes_globals/string/trim/index.html | 123 -------- .../objectes_globals/string/trimleft/index.html | 94 ------ .../objectes_globals/string/trimright/index.html | 94 ------ 30 files changed, 3964 deletions(-) delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/anchor/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/big/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/blink/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/bold/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/charat/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/concat/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/endswith/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/fixed/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/fontcolor/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/fontsize/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/fromcharcode/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/indexof/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/italics/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/length/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/link/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/normalize/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/small/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/startswith/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/sub/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/substr/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/sup/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/tolocalelowercase/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/tolocaleuppercase/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/tolowercase/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/tostring/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/touppercase/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/trim/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/trimleft/index.html delete mode 100644 files/ca/web/javascript/referencia/objectes_globals/string/trimright/index.html (limited to 'files/ca/web/javascript/referencia/objectes_globals/string') diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/anchor/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/anchor/index.html deleted file mode 100644 index 15bd4db97b..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/anchor/index.html +++ /dev/null @@ -1,118 +0,0 @@ ---- -title: String.prototype.anchor() -slug: Web/JavaScript/Referencia/Objectes_globals/String/anchor -translation_of: Web/JavaScript/Reference/Global_Objects/String/anchor ---- -
{{JSRef}}
- -

El mètode anchor() un element àncora HTML {{HTMLElement("a")}} que s'utilitza com a HTML un objectiu hypertext.

- -

Sintaxi

- -
str.anchor(nom)
- -

Paràmetres

- -
-
nom
-
Una cadena que representa l'atribut name attribute of the a tag to be created.
-
- -

Descripció

- -

Utilitzar el mètode anchor() per crear i mostrar una àncora en un document mitjançant programació.

- -

En la sintaxi, la cadena de text representa el text literal que es vol mostrar a l'usuari. La cadena paràmetre name representa l'atribut name de l'element {{HTMLElement("a")}}.

- -

Les àncores creades amb el mètode anchor() es tornen elements de l'array {{domxref("document.anchors")}}.

- -

Exemples

- -

Utilitzar anchor()

- -
var myString = 'Taula de continguts';
-
-document.body.innerHTML = myString.anchor('contents_anchor');
-
- -

Mostrarà el següent HTML:

- -
<a name="contents_anchor">Taula de continguts</a>
-
- -

Especificacions

- - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-string.prototype.anchor', 'String.prototype.anchor')}}{{Spec2('ES6')}}Definició inicial. Implementat en JavaScript 1.0. Definit en l'Annex B (normative) per característiques addiccionals d'ECMAScript per a navegadors Web.
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.0")}} [1]{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome pdr AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("1.0")}} [1]{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

[1] Des de la versió Gecko 17, les " (cometes) són substituides pel caràcter de referència HTML &quot; en cadenes subministrades pel paràmetre name.

- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/big/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/big/index.html deleted file mode 100644 index a3b8815f10..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/big/index.html +++ /dev/null @@ -1,114 +0,0 @@ ---- -title: String.prototype.big() -slug: Web/JavaScript/Referencia/Objectes_globals/String/big -translation_of: Web/JavaScript/Reference/Global_Objects/String/big ---- -
{{JSRef}} {{deprecated_header}}
- -

El mètode big() crea un element HTML {{HTMLElement("big")}} que causa que la cadena es mostri en una font de mida gran.

- -
-

Nota d'ús: L'element <big> s'ha eliminat de l'HTML5 i no s'hauria de fer servir més. S'aconsella als desenvolupadors web utilitzar les propietats de CSS.

-
- -

Sintaxi

- -
str.big()
- -

Descripció

- -

El mètode big() incrusta una cadena dins del tag <big>: "<big>str</big>".

- -

Exemples

- -

Utilitzar big()

- -

L'exemple següent utilitza mètodes string per canviar la mida d'una cadena:

- -
var worldString = 'Hello, world';
-
-console.log(worldString.small());     // <small>Hello, world</small>
-console.log(worldString.big());       // <big>Hello, world</big>
-console.log(worldString.fontsize(7)); // <fontsize=7>Hello, world</fontsize>
-
- -

Amb l'objecte {{domxref("HTMLElement.style", "element.style")}} es pot obtenir l'atribut style de l'element i manipular-lo més genèricament, per exemple:

- -
document.getElementById('yourElemId').style.fontSize = '2em';
-
- -

Especificacions

- - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-string.prototype.big', 'String.prototype.big')}}{{Spec2('ES6')}}Definició inicial. Implementat en JavaScript 1.0. Definit en l'Annex B (normative) per característiques addicionals ECMAScript per navegadors web.
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/blink/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/blink/index.html deleted file mode 100644 index 2378325897..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/blink/index.html +++ /dev/null @@ -1,110 +0,0 @@ ---- -title: String.prototype.blink() -slug: Web/JavaScript/Referencia/Objectes_globals/String/blink -translation_of: Web/JavaScript/Reference/Global_Objects/String/blink ---- -
{{JSRef}} {{deprecated_header}}
- -

El mètode blink() crea un elment HTML {{HTMLElement("blink")}} que fa mostrar una cadena de forma intermitent.

- -
-

Advertència: El text que es mostra de forma intermitent és mal vist per varis estàndards d'accessibilitat. L'element  <blink> no és estàndard i és obsolet!

-
- -

Sintaxi

- -
str.blink()
- -

Descripció

- -

El mètode blink() incrusta una cadena dins l'etiqueta <blink>: "<blink>cad</blink>".

- -

Exemples

- -

Utilitzar blink()

- -

L'exemple següent utilitza mètodes string per canviar el format d'una cadena:

- -
var worldString = 'Hello, world';
-
-console.log(worldString.blink());   // <blink>Hello, world</blink>
-console.log(worldString.bold());    // <b>Hello, world</b>
-console.log(worldString.italics()); // <i>Hello, world</i>
-console.log(worldString.strike());  // <strike>Hello, world</strike>
- -

Especificacions

- - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-string.prototype.blink', 'String.prototype.blink')}}{{Spec2('ES6')}}Definició inicial. Implementat en JavaScript 1.0. Definit en l'Annex B (normative) per característiques addiccionals d'ECMAScrip per Navegadors Web.
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/bold/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/bold/index.html deleted file mode 100644 index 502810bb45..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/bold/index.html +++ /dev/null @@ -1,106 +0,0 @@ ---- -title: String.prototype.bold() -slug: Web/JavaScript/Referencia/Objectes_globals/String/bold -translation_of: Web/JavaScript/Reference/Global_Objects/String/bold ---- -
{{JSRef}} {{deprecated_header}}
- -

El mètode bold() crea un element HTML {{HTMLElement("b")}} que causa que una cadena es mostri amb negreta.

- -

Sintaxi

- -
str.bold()
- -

Descripció

- -

El mètode bold() incrusta una cadena en l'etiqueta <b>: "<b>cad</b>".

- -

Exemples

- -

Utilitzar bold()

- -

L'exemple següent utilitza mètodes string per canviar el format d'una cadena:

- -
var worldString = 'Hello, world';
-
-console.log(worldString.blink());   // <blink>Hello, world</blink>
-console.log(worldString.bold());    // <b>Hello, world</b>
-console.log(worldString.italics()); // <i>Hello, world</i>
-console.log(worldString.strike());  // <strike>Hello, world</strike>
- -

Especificacions

- - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-string.prototype.bold', 'String.prototype.bold')}}{{Spec2('ES6')}}Definició inicial. Implementat en JavaScript 1.0. Definit en l'Annex B (normative) per Característiques addiccionals ECMAScript per navegadors Web.
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/charat/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/charat/index.html deleted file mode 100644 index 55a84ab7d0..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/charat/index.html +++ /dev/null @@ -1,283 +0,0 @@ ---- -title: String.prototype.charAt() -slug: Web/JavaScript/Referencia/Objectes_globals/String/charAt -translation_of: Web/JavaScript/Reference/Global_Objects/String/charAt ---- -
{{JSRef}}
- -

El mètode charAt() retorna el caràcter especificat d'una cadena.

- -

Sintaxi

- -
str.charAt(posicio)
- -

Paràmetres

- -
-
posicio
-
Un nombre sencer entre 0 i la longitud de la cadena menys 1.
-
- -

Descripció

- -

Els caràcters d'una cadena reben un nombre per la seva posició d'esquerra a dreta. La posició del primer caràcter és el 0 i la posició de l'últim caràcter d'una cadena anomenada stringName és stringName.length - 1. Si la posicio proporcionada està fora del rang vàlid JavaScript retornarà una cadena buida.

- -

Exemples

- -

Mostrar caràcters de diferents posicions d'una cadena

- -

L'exemple següent mostra alguns caràcters a diferents posicions de la cadena "Brave new world":

- -
var anyString = 'Brave new world';
-
-console.log("El caràcter a la posició 0   és '" + anyString.charAt(0)   + "'");
-console.log("El caràcter a la posició 1   és '" + anyString.charAt(1)   + "'");
-console.log("El caràcter a la posició 2   és '" + anyString.charAt(2)   + "'");
-console.log("El caràcter a la posició 3   és '" + anyString.charAt(3)   + "'");
-console.log("El caràcter a la posició 4   és '" + anyString.charAt(4)   + "'");
-console.log("El caràcter a la posició 999 és '" + anyString.charAt(999) + "'");
-
- -

Les línies anteriors mostren la sortida següent:

- -
El caràcter a la posició 0   és 'B'
-El caràcter a la posició 1   és 'r'
-El caràcter a la posició 2   és 'a'
-El caràcter a la posició 3   és 'v'
-El caràcter a la posició 4   és 'e'
-El caràcter a la posició 999 és ''
-
- -

Obtenir caràcters sencers

- -

El codi següent garanteix obtenir un caràcter sencer, fins i tot quan la cadena contingui caràcters que no formen part del pla bàsic multilingüístic.

- -
var str = 'A \uD87E\uDC04 Z'; // We could also use a non-BMP character directly
-for (var i = 0, chr; i < str.length; i++) {
-  if ((chr = getWholeChar(str, i)) === false) {
-    continue;
-  }
-  // Adapt this line at the top of each loop, passing in the whole string and
-  // the current iteration and returning a variable to represent the
-  // individual character
-
-  console.log(chr);
-}
-
-function getWholeChar(str, i) {
-  var code = str.charCodeAt(i);
-
-  if (Number.isNaN(code)) {
-    return ''; // Position not found
-  }
-  if (code < 0xD800 || code > 0xDFFF) {
-    return str.charAt(i);
-  }
-
-  // High surrogate (could change last hex to 0xDB7F to treat high private
-  // surrogates as single characters)
-  if (0xD800 <= code && code <= 0xDBFF) {
-    if (str.length <= (i + 1)) {
-      throw 'High surrogate without following low surrogate';
-    }
-    var next = str.charCodeAt(i + 1);
-      if (0xDC00 > next || next > 0xDFFF) {
-        throw 'High surrogate without following low surrogate';
-      }
-      return str.charAt(i) + str.charAt(i + 1);
-  }
-  // Low surrogate (0xDC00 <= code && code <= 0xDFFF)
-  if (i === 0) {
-    throw 'Low surrogate without preceding high surrogate';
-  }
-  var prev = str.charCodeAt(i - 1);
-
-  // (could change last hex to 0xDB7F to treat high private
-  // surrogates as single characters)
-  if (0xD800 > prev || prev > 0xDBFF) {
-    throw 'Low surrogate without preceding high surrogate';
-  }
-  // We can pass over low surrogates now as the second component
-  // in a pair which we have already processed
-  return false;
-}
-
- -

En l'entorn de l'ECMAScript 2016, que soporta assignació desestructurada, es pot utilitzar el codi següent com a versió alternativa més flexibleenvironment which allows destructured assignment, the following is a more succinct and somewhat more flexible alternative in that it does incrementing for an incrementing variable automatically (if the character warrants it in being a surrogate pair).

- -
var str = 'A\uD87E\uDC04Z'; // We could also use a non-BMP character directly
-for (var i = 0, chr; i < str.length; i++) {
-  [chr, i] = getWholeCharAndI(str, i);
-  // Adapt this line at the top of each loop, passing in the whole string and
-  // the current iteration and returning an array with the individual character
-  // and 'i' value (only changed if a surrogate pair)
-
-  console.log(chr);
-}
-
-function getWholeCharAndI(str, i) {
-  var code = str.charCodeAt(i);
-
-  if (Number.isNaN(code)) {
-    return ''; // Position not found
-  }
-  if (code < 0xD800 || code > 0xDFFF) {
-    return [str.charAt(i), i]; // Normal character, keeping 'i' the same
-  }
-
-  // High surrogate (could change last hex to 0xDB7F to treat high private
-  // surrogates as single characters)
-  if (0xD800 <= code && code <= 0xDBFF) {
-    if (str.length <= (i + 1)) {
-      throw 'High surrogate without following low surrogate';
-    }
-    var next = str.charCodeAt(i + 1);
-      if (0xDC00 > next || next > 0xDFFF) {
-        throw 'High surrogate without following low surrogate';
-      }
-      return [str.charAt(i) + str.charAt(i + 1), i + 1];
-  }
-  // Low surrogate (0xDC00 <= code && code <= 0xDFFF)
-  if (i === 0) {
-    throw 'Low surrogate without preceding high surrogate';
-  }
-  var prev = str.charCodeAt(i - 1);
-
-  // (could change last hex to 0xDB7F to treat high private surrogates
-  // as single characters)
-  if (0xD800 > prev || prev > 0xDBFF) {
-    throw 'Low surrogate without preceding high surrogate';
-  }
-  // Return the next character instead (and increment)
-  return [str.charAt(i + 1), i + 1];
-}
-
- -

Fixing charAt() to support non-Basic-Multilingual-Plane (BMP) characters

- -

While the example above may be more frequently useful for those wishing to support non-BMP characters (since it does not require the caller to know where any non-BMP character might appear), in the event that one does wish, in choosing a character by index, to treat the surrogate pairs within a string as the single characters they represent, one can use the following:

- -
function fixedCharAt(str, idx) {
-  var ret = '';
-  str += '';
-  var end = str.length;
-
-  var surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
-  while ((surrogatePairs.exec(str)) != null) {
-    var li = surrogatePairs.lastIndex;
-    if (li - 2 < idx) {
-      idx++;
-    } else {
-      break;
-    }
-  }
-
-  if (idx >= end || idx < 0) {
-    return '';
-  }
-
-  ret += str.charAt(idx);
-
-  if (/[\uD800-\uDBFF]/.test(ret) && /[\uDC00-\uDFFF]/.test(str.charAt(idx + 1))) {
-    // Go one further, since one of the "characters" is part of a surrogate pair
-    ret += str.charAt(idx + 1);
-  }
-  return ret;
-}
-
- -

Specifications

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('ES1')}}{{Spec2('ES1')}}Initial definition.
{{SpecName('ES5.1', '#sec-15.5.4.4', 'String.prototype.charAt')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string.prototype.charat', 'String.prototype.charAt')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-string.prototype.charat', 'String.prototype.charAt')}}{{Spec2('ESDraft')}} 
- -

Browser compatibility

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

See also

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/concat/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/concat/index.html deleted file mode 100644 index 87cdda3c5e..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/concat/index.html +++ /dev/null @@ -1,125 +0,0 @@ ---- -title: String.prototype.concat() -slug: Web/JavaScript/Referencia/Objectes_globals/String/concat -translation_of: Web/JavaScript/Reference/Global_Objects/String/concat ---- -
{{JSRef}}
- -

El mètode concat() combina el text de dos o més strings i retorna un nou string.

- -

Sintaxi

- -
str.concat(string2, string3[, ..., stringN])
- -

Paràmetres

- -
-
string2...stringN
-
Strings que seran concatenats a aquest string.
-
- -

Descripció

- -

La funció concat() combina el text d'un o més strings i retorna un nou string. Canvis al text d'un string no afecten l'altre string.

- -

Exemples

- -

Utilitzar concat()

- -

L'exemple següent combina strings en un nou string.

- -
var hola = 'Hola, ';
-console.log(hola.concat('Kevin', ' tingueu un bon dia.'));
-
-/* Hola, Kevin tingueu un bon dia. */
-
- -

Rendiment

- -

Es recomana altament utilitzar els {{jsxref("Operators/Assignment_Operators", "operadors d'assignació", "", 1)}} (+, +=) en comptes del mètode concat(). Vegeu aquest test de rendiment.

- -

Especificacions

- - - - - - - - - - - - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES3')}}{{Spec2('ES3')}}Definició inicial. Implementat a JavaScript 1.2.
{{SpecName('ES5.1', '#sec-15.5.4.6', 'String.prototype.concat')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string.prototype.concat', 'String.prototype.concat')}}{{Spec2('ES6')}} 
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/endswith/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/endswith/index.html deleted file mode 100644 index 83a1201549..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/endswith/index.html +++ /dev/null @@ -1,133 +0,0 @@ ---- -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é

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/fixed/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/fixed/index.html deleted file mode 100644 index 069ab4243f..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/fixed/index.html +++ /dev/null @@ -1,103 +0,0 @@ ---- -title: String.prototype.fixed() -slug: Web/JavaScript/Referencia/Objectes_globals/String/fixed -translation_of: Web/JavaScript/Reference/Global_Objects/String/fixed ---- -
{{JSRef}} {{deprecated_header}}
- -

El mètode fixed() crea un element HTML {{HTMLElement("tt")}} que fa que una cadena es mostri en una font fixed-pitch.

- -

Sintaxi

- -
str.fixed()
- -

Descripció

- -

El mètode fixed() incrusta una cadena en una etiqueta <tt>: "<tt>cad</tt>".

- -

Exemples

- -

Utilitzar fixed()

- -

L'exemple següent utilitza el mètode fixed per canviar el format d'una cadena:

- -
var worldString = 'Hello, world';
-console.log(worldString.fixed()); // "<tt>Hello, world</tt>"
-
- -

Especificacions

- - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-string.prototype.fixed', 'String.prototype.fixed')}}{{Spec2('ES6')}}Definició inicial. Implementat en JavaScript 1.0. Definit en l'Annex B (normative) per Característiques addiccionals d'ECMAScript per Navegadors Web.
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/fontcolor/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/fontcolor/index.html deleted file mode 100644 index be52cd576b..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/fontcolor/index.html +++ /dev/null @@ -1,122 +0,0 @@ ---- -title: String.prototype.fontcolor() -slug: Web/JavaScript/Referencia/Objectes_globals/String/fontcolor -translation_of: Web/JavaScript/Reference/Global_Objects/String/fontcolor ---- -
{{JSRef}} {{deprecated_header}}
- -

El mètode fontcolor() crea un element HTML {{HTMLElement("font")}} que fa que una cadena es mostri amb el color font especificat.

- -
-

Nota d'ús: L'element <font> s'ha eleminitat d'HTML5 i no s'ha de fer servir més. Els desenvolupadors web haurien d'utilitzar les propietats de CSS per aquesta finalitat.

-
- -

Sintaxi

- -
str.fontcolor(color)
- -

Paràmetres

- -
-
color
-
Una cadena que expressa el color com a un triplet RGB hexadecimal o com una cadena literal. Les cadenes literals de noms de colors es troben enllistades en la referència de colors de CSS.
-
- -

Descripció

- -

Si expresseu el color com un triplet RGB hexadecimal, heu de fer servir el format rrggbb. Per example, els valors RGB hexadecimals pel color salmó són vermell=FA, verd=80, i blau=72, de forma que el triplet RGB pel color salmó és "FA8072".

- -

Exemples

- -

Utilitzar fontcolor()

- -

L'exemple següent utilitza el mètode fontcolor() per canviar el color d'una cadena mitjançant la creació d'una cadena amb l'etiqueta HTML <font>.

- -
var worldString = 'Hola, món';
-
-console.log(worldString.fontcolor('red') +  ' és vermell en aquesta línia');
-// '<font color="red">Hola, món</font> 's vermell en aquesta línia'
-
-console.log(worldString.fontcolor('FF00') + ' és vermell en hexadecimal en aquesta línia');
-// '<font color="FF00">Hola, món</font> és vermell en hexadecimal en aquesta línia'
-
- -

Amb l'objecte {{domxref("HTMLElement.style", "element.style")}} es pot obtenir l'atribut style de l'element i manipular-lo més genèricament, per exemple:

- -
document.getElementById('yourElemId').style.color = 'red';
-
- -

Especificacions

- - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-string.prototype.fontcolor', 'String.prototype.fontcolor')}}{{Spec2('ES6')}}Definició inicial. Implementat en JavaScript 1.0. Definit en l'Annex B (normative) per Característiques addiccionals d'ECMAScript per Navegadors Web.
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/fontsize/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/fontsize/index.html deleted file mode 100644 index 9f30d124aa..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/fontsize/index.html +++ /dev/null @@ -1,121 +0,0 @@ ---- -title: String.prototype.fontsize() -slug: Web/JavaScript/Referencia/Objectes_globals/String/fontsize -translation_of: Web/JavaScript/Reference/Global_Objects/String/fontsize ---- -
{{JSRef}} {{deprecated_header}}
- -

El mètode fontsize() crea un element HTML {{HTMLElement("font")}} que causa que una cadena es mostri en el tamany font especificat.

- -
-

Nota d'ús: L'element <font> s'ha eliminat de l'HTML5 i no s'ha de fer servir més. Els desenvolupadors web haurien de fer servir les propietats de CSS per aquesta finalitat.

-
- -

Sintaxi

- -
str.fontsize(mida)
- -

Paràmetres

- -
-
mida
-
Un nombre sencer entre 1 i 7, una cadena que representi un nombre sencer amb signe entre 1 i 7.
-
- -

Descripció

- -

Quan s'especifica la mida com a un nombre sencer, s'estableix la mida de la str a un de les 7 mides definides. Quan s'especifica la mida com una cadena com pot ser "-2", s'adjusta el tamany font de str en relació ambel tamany establert en l'etiqueta {{HTMLElement("basefont")}}.

- -

Exemples

- -

Utilitzar fontsize()

- -

El següent exemple utilitza mètodes string per canviar la mida de la cadena:

- -
var worldString = 'Hola, món';
-
-console.log(worldString.small());     // <small>Hola, món</small>
-console.log(worldString.big());       // <big>Hola, món</big>
-console.log(worldString.fontsize(7)); // <font size="7">Hola, món</fontsize>
-
- -

Amb l'objecte {{domxref("HTMLElement.style", "element.style")}} es pot obtenir el atribut style de l'element i manipular-lo més genèricament, per exemple:

- -
document.getElementById('yourElemId').style.fontSize = '0.7em';
-
- -

Especificacions

- - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-string.prototype.fontsize', 'String.prototype.fontsize')}}{{Spec2('ES6')}}Definició inicial. Implementat en JavaScript 1.0. Definit en l'Annex B (normative) per Característiques Addiccionals d'ECMAScript per Navegadors Web.
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/fromcharcode/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/fromcharcode/index.html deleted file mode 100644 index f4e2308bf9..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/fromcharcode/index.html +++ /dev/null @@ -1,126 +0,0 @@ ---- -title: String.fromCharCode() -slug: Web/JavaScript/Referencia/Objectes_globals/String/fromCharCode -translation_of: Web/JavaScript/Reference/Global_Objects/String/fromCharCode ---- -
{{JSRef}}
- -

El mètode estàtic String.fromCharCode() retorna un string creat a partir de la seqüència de valors Unicode especificada.

- -

Sintaxi

- -
String.fromCharCode(num1[, ...[, numN]])
- -

Paràmetres

- -
-
num1, ..., numN
-
Una seqüència de nombres que són valors Unicode.
-
- -

Descripció

- -

Aquest mètode retorna un string i no un objecte de tipus {{jsxref("String")}}.

- -

Com que fromCharCode() és un mètode estàtic de {{jsxref("String")}}, sempre s'utilitza com String.fromCharCode() en comptes de com un mètode d'un objecte {{jsxref("String")}} creat.

- -

Exemples

- -

Utilitzar fromCharCode()

- -

L'exemple següent retorna el string "ABC".

- -
String.fromCharCode(65, 66, 67);  // "ABC"
-
- -

Fer que funcioni amb valors més grans

- -

Tot i que la majoria dels valors Unicode es poden representar amb un nombre de 16 bits (tal i com s'esperava mentre s'estava estandaritzant el JavaScript) i es pot emprar fromCharCode() per a retornar un sol caràcter per als valors més comuns (com ara valors UCS-2, que són un subconjunt de l'UTF-16 amb els caràcters més comuns), per a poder manegar TOTS els valors legals Unicode (els quals requereixen fins a 21 bits),  l'ús de només fromCharCode() no és adequat ja que els caràcters de valor més alt utilitzen dos nombres "substituts" (de menor valor) per a formar un sol caràcter. Es pot emprar {{jsxref("String.fromCodePoint()")}} (que forma part de l'esborrant de l'ECMAScript 6) per a retornar el parell de nombres citat i, d'aquesta forma, representar de manera adequada aquests caràcters de valor més alt.

- -

Especificacions

- - - - - - - - - - - - - - - - - - - - - - - - -
EspecificacionsEstatComentaris
{{SpecName('ES1')}}{{Spec2('ES1')}}Definició inicial. Implementat a JavaScript 1.2.
{{SpecName('ES5.1', '#sec-15.5.3.2', 'StringfromCharCode')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string.fromcharcodes', 'String.fromCharCode')}}{{Spec2('ES6')}} 
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/index.html deleted file mode 100644 index 136820a54d..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/index.html +++ /dev/null @@ -1,340 +0,0 @@ ---- -title: String -slug: Web/JavaScript/Referencia/Objectes_globals/String -translation_of: Web/JavaScript/Reference/Global_Objects/String ---- -
{{JSRef("Global_Objects", "String")}}
- -

Resum

- -

L'objecte global String és un constructor per a strings, també conegudes com a cadenes de caràcters.

- -

Sintaxi

- -

Els literals de tipus Stringpoden tenir les següents formes:

- -
'string text'
-"string text"
-"中文 español English हिन्दी العربية português বাংলা русский 日本語 ਪੰਜਾਬੀ 한국어 தமிழ்"
-
- -

A més dels caràcters imprimibles normals, es poden codificar caràcters especials mitjançant la notació d'escapament:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CodiSortida
\0el caràcter NUL
\'cometa simple
\"cometa doble
\\barra invertida
\nlínia nova
\rretorn de carro
\vbarra vertical
\ttabulador
\besborrar
\fform feed
\uXXXXcaràcter amb codificació unicode
\xXXcaràcter amb codificació Latin-1
- -

O bé utilitzant l'objecte global String de forma directa:

- -
String(quelcom)
-new String(quelcom)
-
- -

Paràmetres

- -
-
quelcom
-
Qualsevol cosa que serà convertida a string.
-
- -

Descripció

- -

Les Strings són útils per a emmagatzemar dades que poden ser representades en forma de texte. Algunes de les operacions més emprades en strings són per a obtindre la seva llargada {{jsxref("String.length", "length")}}, per a concatenar-les mitjançant els operadors de strings + i +=, per a comprovar l'existència o localització de substrings amb el mètode {{jsxref("String.prototype.indexOf()", "indexOf()")}}, o bé per a extreure substrings amb el mètode {{jsxref("String.prototype.substring()", "substring()")}}.

- -

Accés als caràcters

- -

Hi ha dues formes d'accedir a un caràcter individual emmagatzemat dins un string. El primer és el mètode {{jsxref("String.prototype.charAt()", "charAt()")}}:

- -
return 'cat'.charAt(1); // retorna "a"
-
- -

L'altra forma (introduida a ECMAScript 5) és fer anar l'string com si fós un objecte de tipus array, on els caràcters individuals es corresponen a un índex numèric:

- -
return 'cat'[1]; // retorna "a"
-
- -

Utilitzar la notació de claus per a esborrar o bé assignar un valor a un caràcter no funcionarà. Les propietats involucrades no són de tipus no-escriptura i no són configurables. (Vegeu {{jsxref("Object.defineProperty()")}} per a més informació).

- -

Comparar strings

- -

Els desenvolupadors de C disposen de la funció strcmp() per a comparar strings. A JavaScript senzillament es poden utilitzar els operadors major-que i menor-que

- -
var a = 'a';
-var b = 'b';
-if (a < b) { // true
-  print(a + ' és menor que ' + b);
-} else if (a > b) {
-  print(a + ' és major que ' + b);
-} else {
-  print(a + ' i ' + b + ' són iguals.');
-}
-
- -

Es pot obtindre un resultat similar mitjançant el mètode {{jsxref("String.prototype.localeCompare()", "localeCompare()")}}, heredat per les instàncies de String.

- -

Distinció entre les primitives string i els objectes String

- -

Cal recalcar que JavaScript distingeix entre objectes de tipus String i valors primitius de tipus string (El mateix succeeix amb {{jsxref("Global_Objects/Boolean", "Boolean")}} i {{jsxref("Global_Objects/Number", "Numbers")}}

- -

Els literals de tipus string (englobats en cometes simples o dobles) així com strings retornats per crides a l'objecte String en un contexte no constructor (és a dir, sense utilitzar la paraula clau {{jsxref("Operators/new", "new")}}) són strings primitives. JavaScript automàticament converteix primitives a objectes String, de forma que és posible utilitzar mètodes de l'objecte String en strings primitives. En els contextes on s'ha d'invocar un mètode en una primitiva string o es demana la una propietat, JavaScript automàticament embolcallarà la primitiva string amb un objecte String i cridarà el mètode o la propietat corresponent.

- -
var s_prim = 'foo';
-var s_obj = new String(s_prim);
-
-console.log(typeof s_prim); // Escriu "string"
-console.log(typeof s_obj);  // Escriu "object"
-
- -

Les primitives string i els objectes String també donen resultats diferents a l'utilitzar {{jsxref("Global_Objects/eval", "eval()")}}. Les primitives passades a eval són considerades codi font; els objectes String es tracten com qualsevol altre objecte, és a dir, retornan l'objecte. Per exemple:

- -
var s1 = '2 + 2';             // crea una primitiva string
-var s2 = new String('2 + 2'); // crea un objecte String
-console.log(eval(s1));        // escriu el nombre 4
-console.log(eval(s2));        // escriu la string "2 + 2"
-
- -

És per aquestes raons que el codi pot produïr errors quan trobi objectes String però s'esperès una primitiva string, tot i que de forma general els autors no s'han de preocupar per la distinció.

- -

Un objecte String sempre es pot convertir en la seva representació primitiva mitjançant el mètode {{jsxref("String.prototype.valueOf()", "valueOf()")}}.

- -
console.log(eval(s2.valueOf())); // escriu el nombre 4
-
- -
Nota: Per a una altra posible enfocament quant a string a JavaScript llegiu l'article sobre StringView — una representació de strings basada en arrays de tipatge explícit similar a C.
- -

Propietats

- -
-
{{jsxref("String.prototype")}}
-
Permet afegir propietats a un objecte String.
-
- -
{{jsOverrides("Function", "Properties", "prototype")}}
- -

Mètodes

- -
-
{{jsxref("String.fromCharCode()")}}
-
Retorna un string creat a partir de la seqüència de valors Unicode proporcionada.
-
{{jsxref("String.fromCodePoint()")}} {{experimental_inline}}
-
Retorna un string creat a partir de la seqüència de code points proporcionada.
-
{{jsxref("String.raw()")}} {{experimental_inline}}
-
Retorna un string creat a partir de l'string proporcionat sense tindre en compte la codificació.
-
- -
{{jsOverrides("Function", "Methods", "fromCharCode", "fromCodePoint", "raw")}}
- -

Mètodes genèrics de String

- -

Els mètodes de les instàncies de String també estan disponibles a Firefox a partir del JavaScript 1.6 (tot i que no formen part de l'standard ECMAScript) a l'objecte String, així es poden aplicar els mètodes de String a qualsevol objecte:

- -
var num = 15;
-console.log(String.replace(num, /5/, '2'));
-
- -

{{jsxref("Global_Objects/Array", "Generics", "#Array_generic_methods", 1)}} també estàn disponibles als mètodes de {{jsxref("Global_Objects/Array", "Array")}}.

- -

A continuació es mostra un shim per a donar suport als navegadors que no ho suporten:

- -
/*globals define*/
-// Assumes all supplied String instance methods already present
-// (one may use shims for these if not available)
-(function() {
-  'use strict';
-
-  var i,
-    // We could also build the array of methods with the following, but the
-    //   getOwnPropertyNames() method is non-shimable:
-    // Object.getOwnPropertyNames(String).filter(function(methodName) {
-    //   return typeof String[methodName] === 'function';
-    // });
-    methods = [
-      'quote', 'substring', 'toLowerCase', 'toUpperCase', 'charAt',
-      'charCodeAt', 'indexOf', 'lastIndexOf', 'startsWith', 'endsWith',
-      'trim', 'trimLeft', 'trimRight', 'toLocaleLowerCase',
-      'toLocaleUpperCase', 'localeCompare', 'match', 'search',
-      'replace', 'split', 'substr', 'concat', 'slice'
-    ],
-    methodCount = methods.length,
-    assignStringGeneric = function(methodName) {
-      var method = String.prototype[methodName];
-      String[methodName] = function(arg1) {
-        return method.apply(arg1, Array.prototype.slice.call(arguments, 1));
-      };
-    };
-
-  for (i = 0; i < methodCount; i++) {
-    assignStringGeneric(methods[i]);
-  }
-}());
-
- -

Instàncies de String

- -

Propietats

- -
{{page('/ca/docs/Web/JavaScript/Reference/Global_Objects/String/prototype', 'Properties')}}
- -

Mètodes

- -

Mètodes no relacionats amb HTML

- -
{{page('/ca/docs/Web/JavaScript/Reference/Global_Objects/String/prototype', 'Methods_unrelated_to_HTML')}}
- -

Mètodes d'embolcall de HTML

- -
{{page('/ca/docs/Web/JavaScript/Reference/Global_Objects/String/prototype', 'HTML_wrapper_methods')}}
- -

Exemples

- -

Exemple: Conversió de strings

- -

És posible utilitzar String com a una alternativa "més segura" de {{jsxref("String.prototype.toString()","toString()")}}, ja que tot i que normalment també crida el mètode toString() subjacent, també funciona per a {{jsxref("Global_Objects/null", "null")}} i {{jsxref("Global_Objects/undefined", "undefined")}}. Per exemple:

- -
var outputStrings = [];
-for (var i = 0, n = inputValues.length; i < n; ++i) {
-  outputStrings.push(String(inputValues[i]));
-}
-
- -

Especificacions

- - - - - - - - - - - - - - - - - - - - - - - - -
EspecificacióEstatComentari
ECMAScript 1a EdicióStandardDefinició inicial.
{{SpecName('ES5.1', '#sec-15.5', 'String')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string-objects', 'String')}}{{Spec2('ES6')}} 
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatChrome("0.2")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/indexof/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/indexof/index.html deleted file mode 100644 index 9b08b04ded..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/indexof/index.html +++ /dev/null @@ -1,190 +0,0 @@ ---- -title: String.prototype.indexOf() -slug: Web/JavaScript/Referencia/Objectes_globals/String/indexOf -translation_of: Web/JavaScript/Reference/Global_Objects/String/indexOf ---- -
{{JSRef}}
- -

El mètode indexOf() retorna la primera posició dins el {{jsxref("String")}} des del que es crida a la qual es troba el valor proporcionat. Retorna -1 si no es troba el valor donat.

- -

Sintaxi

- -
str.indexOf(valorACercar[, posicioInicial])
- -

Paràmetres

- -
-
valorACercar
-
Un string que representa el valor a cercar.
-
posicioInicial {{optional_inline}}
-
La posició a partir de la qual es cercarà dins la cadena. Pot ser qualsevol nombre sencer. El valor per defecte és 0, indicant que es cercarà a tota la cadena. Si posicioInicial < 0 es cercarà a tota la cadena. Si posicioInicial >= str.length, no es cercarà a la cadena i es retornarà -1 automàticament. Si valorACercar és una cadena buida es retornarà str.length.
-
- -

Descripció

- -

Els caràcters de la cadena s'indexen d'esquerra a dreta. La posició del primer caràcter és 0, i la posició de l'últim caràcter d'una cadena amb nom stringName és  stringName.length - 1.

- -
'Blue Whale'.indexOf('Blue');     // returns  0
-'Blue Whale'.indexOf('Blute');    // returns -1
-'Blue Whale'.indexOf('Whale', 0); // returns  5
-'Blue Whale'.indexOf('Whale', 5); // returns  5
-'Blue Whale'.indexOf('', 9);      // returns  9
-'Blue Whale'.indexOf('', 10);     // returns 10
-'Blue Whale'.indexOf('', 11);     // returns 10
-
- -

Distinció entre majúscules i minúscules

- -

El mètode indexOf() distingeix entre majúscules i minúscules. Per exemple, l'expressió següent retorna -1:

- -
'Blue Whale'.indexOf('blue'); // retorna -1
-
- -

Comprovar troballes

- -

Cal destacar que '0' no s'evalua a true i que '-1' no s'evalua a false. Tenim llavors que al comprovar si una cadena específica existeix dins una altra, la forma correcta de comprovar-ho seria:

- -
'Blue Whale'.indexOf('Blue') !== -1; // true
-'Blue Whale'.indexOf('Bloe') !== -1; // false
-
- -

Exemples

- -

Utilitzar indexOf() i lastIndexOf()

- -

L'exemple següent utilitza indexOf() i {{jsxref("String.prototype.lastIndexOf()", "lastIndexOf()")}} per a trobar valors dins la cadena "Brave new world".

- -
var anyString = 'Brave new world';
-
-console.log('La posicó de la primera w des del principi és ' + anyString.indexOf('w'));
-// mostra 8
-console.log('La posició de la primera w des del final és ' + anyString.lastIndexOf('w'));
-// mostra 10
-
-console.log('La posicó de "new" des del principi és ' + anyString.indexOf('new'));
-// mostra 6
-console.log('La posició de "new" des del final és ' + anyString.lastIndexOf('new'));
-// mostra 6
-
- -

indexOf() i distinció entre majúscules i minúscules

- -

L'exemple següent definteix dos variables de tipus cadena. The following example defines two string variables. The variables contain the same string except that the second string contains uppercase letters. The first {{domxref("console.log()")}} method displays 19. But because the indexOf() method is case sensitive, the string "cheddar" is not found in myCapString, so the second console.log() method displays -1.

- -
var myString    = 'brie, pepper jack, cheddar';
-var myCapString = 'Brie, Pepper Jack, Cheddar';
-
-console.log('myString.indexOf("cheddar") is ' + myString.indexOf('cheddar'));
-// logs 19
-console.log('myCapString.indexOf("cheddar") is ' + myCapString.indexOf('cheddar'));
-// logs -1
-
- -

Using indexOf() to count occurrences of a letter in a string

- -

The following example sets count to the number of occurrences of the letter e in the string str:

- -
var str = 'To be, or not to be, that is the question.';
-var count = 0;
-var pos = str.indexOf('e');
-
-while (pos !== -1) {
-  count++;
-  pos = str.indexOf('e', pos + 1);
-}
-
-console.log(count); // displays 4
-
- -

Specifications

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('ES1')}}{{Spec2('ES1')}}Initial definition.
{{SpecName('ES5.1', '#sec-15.5.4.7', 'String.prototype.indexOf')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string.prototype.indexof', 'String.prototype.indexOf')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-string.prototype.indexof', 'String.prototype.indexOf')}}{{Spec2('ESDraft')}} 
- -

Browser compatibility

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

See also

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/italics/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/italics/index.html deleted file mode 100644 index f38a8f9579..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/italics/index.html +++ /dev/null @@ -1,104 +0,0 @@ ---- -title: String.prototype.italics() -slug: Web/JavaScript/Referencia/Objectes_globals/String/italics -translation_of: Web/JavaScript/Reference/Global_Objects/String/italics ---- -
{{JSRef}} {{deprecated_header}}
- -

El mètode italics() crea un element HTML {{HTMLElement("i")}} que converteix una cadena en format itàlic.

- -

Sintaxi

- -
str.italics()
- -

Descripció

- -

El mètode italics() incrusta una cadena en una etiqueta <i>: "<i>str</i>".

- -

Exemples

- -

Utilitzar italics()

- -

L'exemple següent utilitza mètodes string per canviar el format de la cadena:

- -
var worldString = 'Hola, món'; console.log(worldString.blink());  // Hello, world
-console.log(worldString.bold());  // Hola, món
-console.log(worldString.italics()); //Hola, món
-console.log(worldString.strike());  // Hola, món
- -

Especificacions

- - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-string.prototype.italics', 'String.prototype.italics')}}{{Spec2('ES6')}}Definició inicial. Implemtat en JavaScript 1.0. Definit en l'Annex B (normative) per Caracerístiques Adiccionals d'ECMAScript per navegadors Web.
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/length/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/length/index.html deleted file mode 100644 index 63a3114d2d..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/length/index.html +++ /dev/null @@ -1,121 +0,0 @@ ---- -title: String.length -slug: Web/JavaScript/Referencia/Objectes_globals/String/length -translation_of: Web/JavaScript/Reference/Global_Objects/String/length ---- -
{{JSRef("Global_Objects", "String")}}
- -

Resum

- -

La propietat length representa la longitud d'una cadena de caràcters.

- -

Sintaxi

- -
str.length
- -

Descripció

- -

Aquesta propietat retorna el nombre d'unitats de codi en un string. {{interwiki("wikipedia", "UTF-16")}}, el format de string utilitzar a JavaScript, utilitza un únic codi de 16 bits per a representar els caràcters més comuns, però necessita dos unitats de codi per a caràcters menys comuns, així que és possible que el valor retornat per length no encaixi amb el nombre de caràcters reals a la cadena de caràcters.

- -

Per a una cadena buida, length és 0.

- -

La propietat estàtica String.length retorna el valor 1.

- -

Exemples

- -

Exemple: Ús bàsic

- -
var x = 'Mozilla';
-var empty = '';
-
-console.log('Mozilla té ' + x.length + ' unitats de codi');
-/* "Mozilla té 7 unitats de codi" */
-
-console.log('La string buida té una longitud de ' + empty.length);
-/* "La string buida té una longitud de 0" */
-
- -

Especificacions

- - - - - - - - - - - - - - - - - - - - - - - - -
EspecificacionsEstatComentaris
ECMAScript 1a Edició.StandardDefinició inicial. Implementat a JavaScript 1.0.
{{SpecName('ES5.1', '#sec-15.5.5.1', 'String.prototype.length')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-properties-of-string-instances-length', 'String.prototype.length')}}{{Spec2('ES6')}} 
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/link/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/link/index.html deleted file mode 100644 index efe1385ddc..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/link/index.html +++ /dev/null @@ -1,119 +0,0 @@ ---- -title: String.prototype.link() -slug: Web/JavaScript/Referencia/Objectes_globals/String/link -translation_of: Web/JavaScript/Reference/Global_Objects/String/link ---- -
{{JSRef}}
- -

El mètode link() crea un element HTML {{HTMLElement("a")}} que causa que una cadena es mostri com un enllaç hipertext a una altra URL.

- -

Sintaxi

- -
str.link(url)
- -

Paràmetres

- -
-
url
-
Una cadena que especifica l'atribut href de l'etiqueta <a>: hauria de ser una URL vàlida (relativa o absoluta), amb qualsevols caràcters escapats & com &amp;, i qualsevol caràcter "  escapat com &quot;.
-
- -

Descripció

- -

Use the link() method to create an HTML snippet for a hypertext link. The returned string can then be added to the document via {{domxref("document.write()")}} or {{domxref("element.innerHTML")}}.

- -

Links created with the link() method become elements in the links array of the document object. See {{domxref("document.links")}}.

- -

Exemples

- -

Utilitzar link()

- -

L'exemple següent mostra la paraula "MDN" com a un enllaç hypertext lque retorna a l'usuari a la xarxa de Mozilla Developer.

- -
var hotText = 'MDN';
-var URL = 'https://developer.mozilla.org/';
-
-console.log('Click to return to ' + hotText.link(URL));
-// Click to return to <a href="https://developer.mozilla.org/">MDN</a>
-
- -

Especificacions

- - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-string.prototype.link', 'String.prototype.link')}}{{Spec2('ES6')}}Definició inicial. Implementat en JavaScript 1.0. Definit en l'Annex B (normative) per Característiques Addiccionals d'ECMAScript per Navegadors Web.
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Notes específiques Gecko

- - - -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/normalize/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/normalize/index.html deleted file mode 100644 index 7a6bcef500..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/normalize/index.html +++ /dev/null @@ -1,154 +0,0 @@ ---- -title: String.prototype.normalize() -slug: Web/JavaScript/Referencia/Objectes_globals/String/normalize -translation_of: Web/JavaScript/Reference/Global_Objects/String/normalize ---- -
{{JSRef}}
- -

El mètode normalize() retorna la Forma Normalitzada en Unicode d'un string donat (si el valor passat no és un string, es convertirà a string primer).

- -

Sintaxi

- -
str.normalize([forma])
- -

Paràmetres

- -
-
forma
-
Una de les opcions "NFC", "NFD", "NFKC", o "NFKD", que determina quina Forma de Normalització Unicode es farà anar. Si s'omet o es passa {{jsxref("undefined")}} com a paràmetre, s'utilitzarà "NFC" per defecte. -
    -
  • NFC — Normalization Form Canonical Composition.
  • -
  • NFD — Normalization Form Canonical Decomposition.
  • -
  • NFKC — Normalization Form Compatibility Composition.
  • -
  • NFKD — Normalization Form Compatibility Decomposition.
  • -
-
-
- -

Errors llençats

- -
-
{{jsxref("RangeError")}}
-
Es llença un {{jsxref("RangeError")}} si forma no és un dels valors especificats adalt.
-
- -

Descripció

- -

El mètode normalize() retorna la Forma Normalitzada Unicode d'un string. No afecta el propi valor del string passat sino que en retorna un de nou.

- -

Exemples

- -

Utilitzar normalize()

- -
// String inicial
-
-// U+1E9B: LLETRA S PETITA DEL LLATÍ AMB UN PUNT A SOBRE
-// U+0323: COMBINACIÓ AMB EL PUNT A SOTA
-var str = '\u1E9B\u0323';
-
-
-// Canonically-composed form (NFC)
-
-// U+1E9B: LLETRA S PETITA DEL LLATÍ AMB UN PUNT A SOBRE
-// U+0323: COMBINACIÓ AMB EL PUNT A SOTA
-str.normalize('NFC'); // '\u1E9B\u0323'
-str.normalize();      // el mateix que a sobre
-
-
-// Canonically-decomposed form (NFD)
-
-// U+017F: LLETRA S PETITA DEL LLATÍ AMB UN PUNT A SOBRE
-// U+0323: COMBINACIÓ AMB EL PUNT A SOTA
-// U+0307: COMBINACIÓ AMB EL PUNT A SOBRE
-str.normalize('NFD'); // '\u017F\u0323\u0307'
-
-
-// Compatibly-composed (NFKC)
-
-// U+1E69: LLETRA S PETITA DEL LLATÍ AMB UN PUNT A SOBRE
-str.normalize('NFKC'); // '\u1E69'
-
-
-// Compatibly-decomposed (NFKD)
-
-// U+0073: LLETRA S PETITA DEL LLATÍ
-// U+0323: COMBINACIÓ AMB EL PUNT A SOTA
-// U+0307: COMBINACIÓ AMB EL PUNT A SOBRE
-str.normalize('NFKD'); // '\u0073\u0323\u0307'
-
- -

Especificacions

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

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatChrome("34")}}{{CompatGeckoDesktop("31")}}{{CompatIE("11")}}{{CompatVersionUnknown}}{{CompatNo}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatChrome("34")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/small/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/small/index.html deleted file mode 100644 index 761797bdda..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/small/index.html +++ /dev/null @@ -1,110 +0,0 @@ ---- -title: String.prototype.small() -slug: Web/JavaScript/Referencia/Objectes_globals/String/small -translation_of: Web/JavaScript/Reference/Global_Objects/String/small ---- -
{{JSRef}} {{deprecated_header}}
- -

El mètode small() crea un element HTML {{HTMLElement("small")}} que causa que una cadena es mostri amb una font petita.

- -

Sintaxi

- -
str.small()
- -

Descripció

- -

El mètode small() incrusta una adena en una etiqueta <small>: "<small>str</small>".

- -

Exemples

- -

Utilitzar small()

- -

L'exemple següent utilitza mètodes string per canviar la mida d'una cadena:

- -
var worldString = 'Hola, món';
-
-console.log(worldString.small());     // <small>Hola, món</small>
-console.log(worldString.big());       // <big>Hola, món</big>
-console.log(worldString.fontsize(7)); // <font size="7">Hola, món</fontsize>
-
- -

Amb l'objecte {{domxref("HTMLElement.style", "element.style")}} es pot obtenir l'atribut style  d'un element i manipular-lo més genèricament. Per exemple:

- -
document.getElementById('yourElemId').style.fontSize = '0.7em';
-
- -

Especificacions

- - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-string.prototype.small', 'String.prototype.small')}}{{Spec2('ES6')}}Definició inicial. Implementat en JavaScript 1.0. Definit en l'Annex B (normative) per Característiques Addiccionals d'ECMAScript per Navegadors Web.
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/startswith/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/startswith/index.html deleted file mode 100644 index ca25398d51..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/startswith/index.html +++ /dev/null @@ -1,128 +0,0 @@ ---- -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é

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/sub/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/sub/index.html deleted file mode 100644 index 0b512d038e..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/sub/index.html +++ /dev/null @@ -1,109 +0,0 @@ ---- -title: String.prototype.sub() -slug: Web/JavaScript/Referencia/Objectes_globals/String/sub -translation_of: Web/JavaScript/Reference/Global_Objects/String/sub ---- -
{{JSRef}} {{deprecated_header}}
- -

El mètode sub() crea un element HTML {{HTMLElement("sub")}} que fa que una cadena es mostri com a subíndex.

- -

Sintaxi

- -
str.sub()
- -

Descripció

- -

El mètode sub() incrusta una cadena a una etiqueta <sub>: "<sub>str</sub>".

- -

Exemples

- -

Utilitzar els mètodes sub() i sup()

- -

El codi següent utiltza els mètodes sub() i {{jsxref("String.prototype.sup()", "sup()")}} per donar format a una cadena:

- -
var superText="superíndex";
-var subText="subíndex";
-
-console.log("Així es com es veu un " + superText.sup());
-// Així es com es veu un <sup>superíndex</sup>.
-
-console.log("Així es com es veu un " + subText.sub());
-// Així es com es veu un <sub>subíndex</sub>.
-
- -

Especificacions

- - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-string.prototype.sub', 'String.prototype.sub')}}{{Spec2('ES6')}} -

Definició inicial. Implementat en JavaScript 1.0. Definit en l'Annex B (normative) per a Característiques Addicicionals d'ECMAScript per Navegadors Web.

-
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/substr/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/substr/index.html deleted file mode 100644 index 5fdb1f03b4..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/substr/index.html +++ /dev/null @@ -1,156 +0,0 @@ ---- -title: String.prototype.substr() -slug: Web/JavaScript/Referencia/Objectes_globals/String/substr -translation_of: Web/JavaScript/Reference/Global_Objects/String/substr ---- -
{{JSRef}}
- -

El mètode substr() retorna els caràcters d'una cadena començant per la posició especificada fins al nombre especificat de caràcters.

- -

Sintaxi

- -
str.substr(començament[, llargària])
- -

Paràmetres

- -
-
començament
-
Lloc des d'on es comença a extraure els caràcters. Si es dóna un nombre negatiu, se'l tracta com strLength + començament on strLength és la llargària de al cadena (per exemple, si començament és -3 se'l tracta com strLength - 3.)
-
llargària
-
Opcional. El nombre de caràcter per extraure.
-
- -

Descripció

- -

començament is a character index. L'índex del primer caràcter és 0, i l'índex de l'últim caràcter és 1 menys que la llargària de la cadena. substr() comença extraient caràcters a començament i recull els caràcters llargària (llevat que primer s'arribi al final de la cadena, en aquest cas en retornaria menys).

- -

Si començament és positivu i més gran o igual que la llargària de la cadena, substr() retornarà una cadena buida.

- -

SI començament és negatiu, substr() l'utilitza com un índex de caràcter des del final de la cadena. Si començament és negatiu i  abs(comença,ent) és més gran que la llargària de la cadena, substr() utilitza 0 com a índex d'inici. Nota: El maneig de valors negatius de l'argument començament no està suportat per Microsoft JScript.

- -

Si llargària és 0 o negatiu, substr() retorna una cadena buida. Si llargària s'omet, substr() extreu els caràcter fins al final de la cadena.

- -

Exemples

- -

Utilitzar substr()

- -
var str = 'abcdefghij';
-
-console.log('(1, 2): '   + str.substr(1, 2));   // '(1, 2): bc'
-console.log('(-3, 2): '  + str.substr(-3, 2));  // '(-3, 2): hi'
-console.log('(-3): '     + str.substr(-3));     // '(-3): hij'
-console.log('(1): '      + str.substr(1));      // '(1): bcdefghij'
-console.log('(-20, 2): ' + str.substr(-20, 2)); // '(-20, 2): ab'
-console.log('(20, 2): '  + str.substr(20, 2));  // '(20, 2): '
-
- -

Polyfill

- -

Microsoft's JScript no suporta valors negatius per l'índex d'inici. Si desitjes utilitzar aquesta característica, pots utilitzar el codi de compatibilitat següent per evitar aquest error:

- -
// només s'executa quan la funció substr() està trencada
-if ('ab'.substr(-1) != 'b') {
-  /**
-   *  Obtenir la subcadena d'una cadena
-   *  @param  {integer}  start   on comença la subcadena
-   *  @param  {integer}  length  quants caràcters s'han de retornar
-   *  @return {string}
-   */
-  String.prototype.substr = function(substr) {
-    return function(start, length) {
-      // crida el mètode original
-      return substr.call(this,
-      	// Si ens dóna un començament negatiu, calcular quant es des de l'inici de la cadena
-        // adjustar el paràmetre start per valor negatiu
-        start < 0 ? this.length + start : start,
-        length)
-    }
-  }(String.prototype.substr);
-}
-
- -

Especificacions

- - - - - - - - - - - - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES3')}}{{Spec2('ES3')}}Definit en l'Annex B de Compatibilitat (informative). Implementat en JavaScript 1.0.
{{SpecName('ES5.1', '#sec-B.2.3', 'String.prototype.substr')}}{{Spec2('ES5.1')}}Definit en l'Annex B de Compatibilitat (informative)
{{SpecName('ES6', '#sec-string.prototype.substr', 'String.prototype.substr')}}{{Spec2('ES6')}}Definit en l'Annex B (normative) per Característiques addiccionals d'ECMAScript per Navegadors Web
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/sup/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/sup/index.html deleted file mode 100644 index 24b46c88ce..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/sup/index.html +++ /dev/null @@ -1,107 +0,0 @@ ---- -title: String.prototype.sup() -slug: Web/JavaScript/Referencia/Objectes_globals/String/sup -translation_of: Web/JavaScript/Reference/Global_Objects/String/sup ---- -
{{JSRef}} {{deprecated_header}}
- -

El mètode sup() crea un element HTML {{HTMLElement("sup")}} que causa que la cadena es mostri com un superíndex.

- -

Sintaxi

- -
str.sup()
- -

Descripció

- -

El mètode sup() incrusta una cadena en l'etiqueta <sup>:"<sup>str</sup>".

- -

Exemples

- -

Utilitzar els mètodes sub() i sup()

- -

L'exemple següent utilitza els mètodes {{jsxref("String.prototype.sub()", "sub()")}} i sup() per formatejar la cadena:

- -
var superText = 'superíndex';
-var subText = 'subíndex';
-
-console.log('This is what a ' + superText.sup());
-// "Així es com es veu un <sup>superíndex</sup>."
-
-console.log('This is what a ' + subText.sub());
-// "Així es com es veu un <sub>subíndex</sub>."
-
- -

Especificacions

- - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-string.prototype.sup', 'String.prototype.sup')}}{{Spec2('ES6')}}Definició inicial. Implementat en JavaScript 1.0. Definit en l'Annex B (normative) per a Característiques Addicicionals d'ECMAScript per Navegadors Web.
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/tolocalelowercase/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/tolocalelowercase/index.html deleted file mode 100644 index c138197bc1..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/tolocalelowercase/index.html +++ /dev/null @@ -1,110 +0,0 @@ ---- -title: String.prototype.toLocaleLowerCase() -slug: Web/JavaScript/Referencia/Objectes_globals/String/toLocaleLowerCase -translation_of: Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase ---- -
{{JSRef}}
- -

El mètode toLocaleLowerCase() retorna el valor del string que fa la crida convertit a minúscules , tot seguint les directrius locals específiques de conversió a minúscules.

- -

Sintaxi

- -
str.toLocaleLowerCase()
- -

Descripció

- -

El mètode toLocaleLowerCase() retorna el valor del string que fa la crida convertit a minúscules , tot seguint les directrius locals específiques de conversió a minúscules.El mètode toLocaleLowerCase() retorna el valor del string que fa la crida convertit a minúscules , tot seguint les directrius locals específiques de conversió a minúscules. En la majoria dels casos, la crida a aquest mètode produirà un resultat similar a la del mètode {{jsxref("String.prototype.toLowerCase()", "toLowerCase()")}}, però per a algunes localitzacions, com ara el Turc, en les quals el pas de majúscules a minúscules o de minúscules a majúscules no segueix les assignacions per defecte del Unicode, el resultat pot diferir.

- -

Exemples

- -

Utilitzar toLocaleLowerCase()

- -
console.log('ALFABET'.toLocaleLowerCase()); // 'alfabet'
-
- -

Especifications

- - - - - - - - - - - - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES3')}}{{Spec2('ES3')}}Definició inicial. Implementat a JavaScript 1.2.
{{SpecName('ES5.1', '#sec-15.5.4.17', 'String.prototype.toLocaleLowerCase')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string.prototype.tolocalelowercase', 'String.prototype.toLocaleLowerCase')}}{{Spec2('ES6')}} 
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/tolocaleuppercase/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/tolocaleuppercase/index.html deleted file mode 100644 index 8f7b2aa716..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/tolocaleuppercase/index.html +++ /dev/null @@ -1,110 +0,0 @@ ---- -title: String.prototype.toLocaleUpperCase() -slug: Web/JavaScript/Referencia/Objectes_globals/String/toLocaleUpperCase -translation_of: Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase ---- -
{{JSRef}}
- -

El mètode toLocaleUpperCase() retorna el valor del string que fa la crida convertit a majúscules, tot seguint les directrius locals específiques de conversió a majúscules.

- -

Sintaxi

- -
str.toLocaleUpperCase()
- -

Descripció

- -

El mètode toLocaleUpperCase() retorna el valor del string que fa la crida convertit a majúscules, tot seguint les directrius locals específiques de conversió a majúscules. toLocaleUpperCase() no afecta el valor del string que fa la crida sino que en retorna un de nou. En la majoria dels casos, la crida a aquest mètode produirà un resultat similar a la del mètode {{jsxref("String.prototype.toUpperCase()", "toUpperCase()")}}, però per a algunes localitzacions, com ara el Turc, en les quals el pas de majúscules a minúscules o de minúscules a majúscules no segueix les assignacions per defecte del Unicode, el resultat pot diferir.

- -

Exemples

- -

Utilitzar toLocaleUpperCase()

- -
console.log('alfabet'.toLocaleUpperCase()); // 'ALFABET'
-
- -

Especificacions

- - - - - - - - - - - - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES3')}}{{Spec2('ES3')}}Definició inicial. Implementat a JavaScript 1.2.
{{SpecName('ES5.1', '#sec-15.5.4.19', 'String.prototype.toLocaleUpperCase')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string.prototype.tolocaleuppercase', 'String.prototype.toLocaleUpperCase')}}{{Spec2('ES6')}} 
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/tolowercase/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/tolowercase/index.html deleted file mode 100644 index 7147d0ea0d..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/tolowercase/index.html +++ /dev/null @@ -1,111 +0,0 @@ ---- -title: String.prototype.toLowerCase() -slug: Web/JavaScript/Referencia/Objectes_globals/String/toLowerCase -translation_of: Web/JavaScript/Reference/Global_Objects/String/toLowerCase ---- -
{{JSRef}}
- -

El mètode toLowerCase() retorna  el valor del string que fa la crida convertit a majúscules.
-  

- -

Sintaxi

- -
str.toLowerCase()
- -

Descripció

- -

El mètode toLowerCase() retorna  el valor del string que fa la crida convertit a majúscules. toLowerCase() no afecta el valor del string que fa la crida sino que en retorna un de nou.

- -

Exemples

- -

Utilitzar toLowerCase()

- -
console.log('ALFABET'.toLowerCase()); // 'alfabet'
-
- -

Especificacions

- - - - - - - - - - - - - - - - - - - - - - - - -
EspecificacionsEstatComentaris
{{SpecName('ES1')}}{{Spec2('ES1')}}Definició inicial. Implementat a JavaScript 1.0.
{{SpecName('ES5.1', '#sec-15.5.4.16', 'String.prototype.toLowerCase')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string.prototype.tolowercase', 'String.prototype.toLowerCase')}}{{Spec2('ES6')}} 
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/tostring/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/tostring/index.html deleted file mode 100644 index 11f2555a2f..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/tostring/index.html +++ /dev/null @@ -1,113 +0,0 @@ ---- -title: String.prototype.toString() -slug: Web/JavaScript/Referencia/Objectes_globals/String/toString -translation_of: Web/JavaScript/Reference/Global_Objects/String/toString ---- -
{{JSRef}}
- -

El mètode toString() retorna un string que representa l'objecte especificat.

- -

Sintaxi

- -
str.toString()
- -

Descripció

- -

L'objecte {{jsxref("String")}} sobreescriu el mètode toString() de l'objecte {{jsxref("Object")}}; no hereta {{jsxref("Object.prototype.toString()")}}. Per a objectes {{jsxref("String")}}, el mètode toString() retorna un string que representa l'objecte i és el mateix que el que el retornat pel mètode {{jsxref("String.prototype.valueOf()")}}.

- -

Exemples

- -

Utilitzar toString()

- -

L'exemple següent mostra el valor d'un objecte {{jsxref("String")}}:

- -
var x = new String('Hello world');
-
-console.log(x.toString()); // mostra 'Hello world'
-
- -

Especificacions

- - - - - - - - - - - - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES3')}}{{Spec2('ES3')}}Definició inicial. Implementat a JavaScript 1.1.
{{SpecName('ES5.1', '#sec-15.5.4.2', 'String.prototype.toString')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string.prototype.tostring', 'String.prototype.toString')}}{{Spec2('ES6')}} 
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/touppercase/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/touppercase/index.html deleted file mode 100644 index 2a3b4fe56a..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/touppercase/index.html +++ /dev/null @@ -1,110 +0,0 @@ ---- -title: String.prototype.toUpperCase() -slug: Web/JavaScript/Referencia/Objectes_globals/String/toUpperCase -translation_of: Web/JavaScript/Reference/Global_Objects/String/toUpperCase ---- -
{{JSRef}}
- -

El mètode toUpperCase() retorna  el valor del string que fa la crida convertit a majúscules.

- -

Sintaxi

- -
str.toUpperCase()
- -

Descripció

- -

El mètode toUpperCase() retorna  el valor del string que fa la crida convertit a majúscules. toUpperCase() no afecta el valor del string que fa la crida sino que en retorna un de nou.

- -

Exemples

- -

Utilitzar toUpperCase()

- -
console.log('alfabet'.toUpperCase()); // 'ALFABET'
-
- -

Especificacions

- - - - - - - - - - - - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES1')}}{{Spec2('ES1')}}Definició inicial. Implementat a JavaScript 1.0.
{{SpecName('ES5.1', '#sec-15.5.4.18', 'String.prototype.toUpperCase')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string.prototype.touppercase', 'String.prototype.toUpperCase')}}{{Spec2('ES6')}} 
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/trim/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/trim/index.html deleted file mode 100644 index 2dd955ea62..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/trim/index.html +++ /dev/null @@ -1,123 +0,0 @@ ---- -title: String.prototype.trim() -slug: Web/JavaScript/Referencia/Objectes_globals/String/Trim -translation_of: Web/JavaScript/Reference/Global_Objects/String/Trim ---- -
{{JSRef}}
- -

El mètode trim() elimina els espais en blanc tant a l'inici com al final del string. En aquest contexte, s'entèn com a espais en blanc tots les caràcters que no imprimeixin res (espai, tabulador, espai sense salt de línia, etcètera) així com tots els caràcters terminadors de línia (LF, CR, etc.).

- -

Sintaxi

- -
str.trim()
- -

Descripció

- -

El mètode trim() retorna un string sense espais en blanc tant a l'inici com al final. trim() no afecta el valor del string ja que en retorna un de nou.

- -

Exemples

- -

Utilitzar trim()

- -

L'exemple següent mostra el string 'foo':

- -
var orig = '   foo  ';
-console.log(orig.trim()); // 'foo'
-
-// Un altre exemple de .trim() eliminant espais en blanc només d'un cantó.
-
-var orig = 'foo    ';
-console.log(orig.trim()); // 'foo'
-
- -

Polyfill

- -

Executar el codi que es mostra a continuació abans d'executar cap altre codi crearà la funció trim() si aquesta no està disponible de forma nativa.

- -
if (!String.prototype.trim) {
-  String.prototype.trim = function () {
-    return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
-  };
-}
-
- -

Especificacions

- - - - - - - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES5.1', '#sec-15.5.4.20', 'String.prototype.trim')}}{{Spec2('ES5.1')}}Definició inicial. Implementat a JavaScript 1.8.1.
{{SpecName('ES6', '#sec-string.prototype.trim', 'String.prototype.trim')}}{{Spec2('ES6')}} 
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.9.1")}}{{CompatIE("9")}}{{CompatOpera("10.5")}}{{CompatSafari("5")}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/trimleft/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/trimleft/index.html deleted file mode 100644 index f16a5b89fa..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/trimleft/index.html +++ /dev/null @@ -1,94 +0,0 @@ ---- -title: String.prototype.trimLeft() -slug: Web/JavaScript/Referencia/Objectes_globals/String/TrimLeft -translation_of: Web/JavaScript/Reference/Global_Objects/String/trimStart ---- -
{{JSRef}} {{non-standard_header}}
- -

El mètode trimLeft() elimina els espais en blanc a l'esquerra del string.

- -

Sintaxi

- -
str.trimLeft()
- -

Descripció

- -

El mètode trimLeft() retorna un string on els espais en blanc del començament s'han eliminat. trimLeft() no afecta al valor mateix del string sino que en retorna un de nou.

- -

Exemples

- -

Utilitzar trimLeft()

- -

L'exemple següent mostra el string 'foo ':

- -
var str = '   foo  ';
-
-console.log(str.length); // 8
-
-str = str.trimLeft();
-console.log(str.length); // 5
-console.log(str);        // 'foo  '
-
- -

Especificacions

- -

No és part de cap standard. Implementat a JavaScript 1.8.1.

- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.9.1")}}{{CompatNo}}{{CompatUnknown}}{{CompatUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
-
- -

Vegeu també

- - diff --git a/files/ca/web/javascript/referencia/objectes_globals/string/trimright/index.html b/files/ca/web/javascript/referencia/objectes_globals/string/trimright/index.html deleted file mode 100644 index 41ab89e3ca..0000000000 --- a/files/ca/web/javascript/referencia/objectes_globals/string/trimright/index.html +++ /dev/null @@ -1,94 +0,0 @@ ---- -title: String.prototype.trimRight() -slug: Web/JavaScript/Referencia/Objectes_globals/String/TrimRight -translation_of: Web/JavaScript/Reference/Global_Objects/String/trimEnd ---- -
{{JSRef}} {{non-standard_header}}
- -

El mètode trimRight() elimina els espais en blanc al final d'un string.

- -

Sintaxi

- -
str.trimRight()
- -

Descripció

- -

El mètode trimRight() retorna el string sense espais en blanc al final del mateix. trimRight() no afecta el valor del string sino que en retorna un de nou.

- -

Exemples

- -

Utilitzar trimRight()

- -

L'exemple següent mostra el string ' foo':

- -
var str = '   foo  ';
-
-console.log(str.length); // 8
-
-str = str.trimRight();
-console.log(str.length); // 5
-console.log(str);        // '   foo'
-
- -

Especificacions

- -

No forma part de cap standard. Implementat a JavaScript 1.8.1.

- -

Browser compatibility

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.9.1")}}{{CompatNo}}{{CompatUnknown}}{{CompatUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
-
- -

Vegeu també

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