34,333
edits
Changes
→JavaScript String Object Examples
== JavaScript String Object Examples ==
Now that we are familiar with the methods and properties provided with the String object it is time to look at some examples.
=== Getting the length of a String Object ===
The length of a string object is obtained by accessing the ''length'' property:
<pre>
myString = new String ("This is my string");
var stringLen = myString.length // assigns length of string to variable stringLen
</pre>
=== Setting String Object text Effects ===
The JavaScript String object provides an extensive range of text effects. The script below shows how to use some of these:
<pre>
myString = new String ("This is my string");
document.writeln ( myString.bold() ); // Displays text in bold
document.writeln ( myString.color("red"); // Displays text in red
document.writeln ( myString.italic()); // Displays text in italics
</pre>
=== Manipulation String Objects ===