String.length

JavaScript1.0+, JScript1.0+, ECMAScript1.0+ NES2+, Nav2+, IE3+, Opera3+ Syntax

							string.length

Description

The length property of an instance of the String object returns the total length of the string.

Example

Listing 6.243 creates three instances of the String object. The length property of each of these instances are accessed and written to the user's page.

Listing 6.243 Accessing the length Property of an Instance of the String Object
 <script language="JavaScript"> <!–– Hide // Create an instance of the String object var myString1 = new String("Hello, World"); var myString2 = new String("Here is a longer string"); var myString3 = new String("Here is an even longer string"); // Write the lengths of these strings to the ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.