What Methods are available with the String object?
The String object holds useful methods for manipulating the character strings you are using within your javascript. These methods can be substituted in your javascript wherever character values are allowed. The String object is pre-defined so does not need to be defined before use. The following simple methods are supported by the String object in all versions of Javascript (there are more advanced methods available in Javascript 1.2 and these will be discussed separately):
- anchor(section_name) puts the string between <a name=> tags
- big() puts the string between <big> tags
- blink() puts the string between <blink> tags
- bold() puts the string between <bold> tags
- charAt(number) selects the single character at the specified position within the string
- fixed() puts the string between <tt> tags
- fontcolor(colour) puts the string between <font color=> tags
- fontsize(number) puts the string between <font size=> tags
- indexOf(substring) finds the position where the specified substring starts
- italics() puts the string between <i> tags
- lastIndexOf(substring) finds the last occurrence of the substring within the string
- link(address) puts the string between <a href=> tags
- small() puts the string between <small> tags
- strike() puts the string between <strike> tags
- sub() puts the string between <sub> tags
- substring(start,end) gets the specified part of the string
- sup() puts the string between <sup> tags
- toLowerCase() convert the string to lowercase
- toUpperCase() convert the string to uppercase
Many of these methods are equivalent to placing the string between the appropriate tags.
For example document.write(mystring.href("index.html"); is equivalent to
document.write('<a href="index.html">' + mystring + '<\/a>');.
Some of these methods are equivalent to surrounding the string with tags that are no longer supported by the latest xhtml version.
Related Articles
- Displaying "Random" Text or Images
- Unobtrusive JavaScripts
- Assigning an Absolute Screen Position Independent of Screen Resolution
- Multiple Dynamic Dropdown Boxes
- What methods are available with the date() function?



