HTML and CSS Reference
Figure 9.27 Output from Example 9.23.
The Properties of the String Object. The string properties (see Table 9.8) describe
the attributes of the String object. The most common string property is the length prop-
erty, which lets you know how many characters there are in a string. The prototype prop-
erty allows you to add your own properties and methods to the String object, that is, you
can customize a string.
Table 9.8 String Object Properties
What It Does
Returns the length of the string in characters.
Returns the function that created the String object.
Extends the definition of the string by adding properties and methods.
<head><title>The String Object</title></head>
<h3>Length of Strings</h3>
var first_string = "The winds of war are blowing.";
var next_string = new String("There is peace in the valley.");
document.write("\""+first_string +"\" contains "+
first_string.length + " characters.");
document.write("<br />\""+ next_string+"\" contains "+
next_string.length +" characters.<br />");
document.write("<font size=-1><em>...not to imply that war
is equal to peace...<br />");