From a55b575e8089ee6cab7c5c262a7e6db55d0e34d6 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:46:50 +0100 Subject: unslug es: move --- .../global_objects/string/length/index.html | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 files/es/web/javascript/reference/global_objects/string/length/index.html (limited to 'files/es/web/javascript/reference/global_objects/string/length') diff --git a/files/es/web/javascript/reference/global_objects/string/length/index.html b/files/es/web/javascript/reference/global_objects/string/length/index.html new file mode 100644 index 0000000000..9401b8898a --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/string/length/index.html @@ -0,0 +1,94 @@ +--- +title: String.length +slug: Web/JavaScript/Referencia/Objetos_globales/String/length +tags: + - JavaScript + - Propiedad + - Prototipo + - Referencia + - String + - length +translation_of: Web/JavaScript/Reference/Global_Objects/String/length +--- +
{{JSRef}}
+ +

La propiedad length de un objeto {{jsxref("String")}} representa la longitud de una cadena, en unidades de código UTF-16.

+ +

Sintaxis

+ +
str.length
+ +

Descripción

+ +

Esta propiedad devuelve el número de caracteres de una cadena. {{interwiki("wikipedia", "UTF-16")}}, el formato usado por JavaScript, usa 16-bit para representar los caracteres más comunes, pero necesita usar dos caracteres para otros menos usados, así que es posible que el valor devuelto por length no corresponda al número de caracteres de la cadena.

+ +

ECMASCript 2016 (ed. 7) estableció una longitud máxima de 2^53 - 1 elementos. Anteriormente, ninguna longitud máxima era especificada. 

+ +

Para una cadena vacía, length es 0.

+ +

La propiedad static String.length devuelve 1.

+ +

Ejemplos

+ +

Uso Básico

+ +
var x = 'Mozilla';
+var empty = '';
+
+console.log('Mozilla is ' + x.length + ' code units long');
+/* "Mozilla is 7 code units long" */
+
+console.log('The empty string has a length of ' + empty.length);
+/* "The empty string has a length of 0" */
+ +

Asignando a length

+ +
var myString = "bluebells";
+
+// Attempting to assign a value to a string's .length property has no observable effect.
+myString.length = 4;
+console.log(myString);
+/* "bluebells" */
+
+ +

Especificaciones

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EspecificaciónEstatusComentario
ECMAScript 1st Edition.EstándarPrimera definicíon. Implementado en 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')}}
{{SpecName('ESDraft', '#sec-properties-of-string-instances-length', 'String.prototype.length')}}{{Spec2('ESDraft')}}
+ +

Compatibilidad con navegadores

+ +

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

+ +

Ver también

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