פונקציה המציגה את האורך של אובייקט המחרוזת בקידוד תווים מסוג UTF-16.

תחביר

str.length

דוגמאות

שימוש סטנדרטי

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" */

אורך מוקצה

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" */

מפרטים

Specification Status Comment
ECMAScript 1st Edition (ECMA-262) Standard Initial definition. Implemented in JavaScript 1.0.
ECMAScript 5.1 (ECMA-262)
The definition of 'String.prototype.length' in that specification.
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'String.prototype.length' in that specification.
Standard  
ECMAScript Latest Draft (ECMA-262)
The definition of 'String.prototype.length' in that specification.
Draft  

תאימות דפדפן

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung InternetNode.js
Basic supportChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes

Legend

Full support  
Full support

Document Tags and Contributors

Contributors to this page: fabio.rahamim
Last updated by: fabio.rahamim,