HTML and CSS Reference
In-Depth Information
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
Property
What It Does
length
Returns the length of the string in characters.
constructor
Returns the function that created the String object.
prototype
Extends the definition of the string by adding properties and methods.
EXAMPLE 9.24
<html>
<head><title>The String Object</title></head>
<body bgColor="lightblue">
<font face="arial">
<big>
<h3>Length of Strings</h3>
<script type="text/javascript">
1
var first_string = "The winds of war are blowing.";
var next_string = new String("There is peace in the valley.");
2
document.write("\""+first_string +"\" contains "+
first_string.length + " characters.");
3
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 />");
</script>
</big>
</font>
</body>
</html>
 
Search WWH ::




Custom Search