JavaScript String Object

Describes the javascript string object including its properties and methods while providing code examples.

Properties

  • length - The number of characters in the string.
  • prototype - For creating more properties

Methods

  • anchor(anchorName) - A string is displayed as an anchor with the name specified.
  • big() - String is displayed in large format. (big tags)
    document.write("This is BIG text".big())
    
    Is the same as:
    <BIG>This is BIG text</BIG>
    

    Producing:

    This is BIG text

  • blink() - String is displayed blinking. (blink tags)
    document.write("This is BLINKING text".blink())
    
    Is the same as:
    <BLINK>This is BLINKING text</BLINK>
    

    Producing:

    This is BLINKING text

  • bold() - String is displayed in bold characters. (bold tags)
    document.write("This is BOLD text".bold())
    
    Is the same as:
    <B>This is BOLD text</B>
    

    Producing:

    This is BOLD text

  • charAt(index) - Returns a string containing the character at the specified location. The example returns the character "r".
    myname = "George"
    myname.charAt(3)
    
  • fixed() - A string is displayed in Teletype format (teletype tags).
    document.write("This is TT text".fixed())
    

    Is the same as:

    <TT>This is TT text</TT>
    

    Producing:

    This is TT text

  • fontcolor(color) - String is displayed in the specified color.
    document.write("This is RED text".fontcolor("red"))
    
    Is the same as:
    <FONT color="red">This is RED text</FONT>
    

    Producing:

    This is RED text

  • fontsize(size) - String is displayed in the specified font from a value of 1 to 7.
    document.write("This is SIZE 5 text".fontsize(5))
    
    Is the same as:
    <FONT size="5">This is SIZE 5 text</FONT>
    

    Producing:

    This is SIZE 5 text

  • indexOf(pattern) - Returns -1 if the value is not found and returns the index of the first character of the first string matching the pattern in the string. The example will return a value of 3.
    myname = "George"
    myname.indexOf("r")
    
  • indexOf(pattern, index) - Returns -1 if the value is not found and returns the index of the first character of the first string matching the pattern in the string. Searching begins at the index value in the string.
  • italics() - String is displayed using the italics tags.
    document.write("This is ITALICS text".italics())
    

    Is the same as:

    <I>This is ITALICS text</I>
    

    Producing:

    This is ITALICS text

  • lastIndexOf(pattern) - Returns -1 if the value is not found and returns the index of the first character of the last string matching the pattern in the string.
  • lastIndexOf(pattern, index) - Returns -1 if the value is not found and returns the index of the first character of the last string matching the pattern in the string. Searching begins at the index value in the string. The example will return a value of 5.
    myname = "George"
    myname.lastIndexOf("e")
    
  • link(href) - A string is displayed as a hypertext link.
    document.write("Computer Technology Documentation Project".link("http://ctdp.tripod.com/"))
    

    Is the same as:

    <A HREF="http://ctdp.tripod.com/">Computer Technology Documentation Project</A>
    

    Producing:

    Computer Technology Documentation Project

  • small() - String is displayed using the small tags.
    document.write("This is SMALL text".small())
    

    Is the same as:

    <SMALL>This is SMALL text</SMALL>
    

    Producing:

    This is SMALL text

  • split(separator) - Splits a string into substrings based on the separator character. In the below example an array called splitValues is created. The splitValues[0] string will be "Day" and the splitValues[0] string will be "Monday".
    nvpair = new String("Day=Monday")
    splitValues=nvpair.split("=")
    
  • strike() - String is displayed using the strikeout tags.
    document.write("This is STRIKEOUT text".strike())
    

    Is the same as:

    <STRIKE>This is STRIKEOUT text</STRIKE>
    

    Producing:

    This is STRIKEOUT text

  • sub() - String is displayed using the subscript tags.
    document.write("This is SUBSCRIPT text".sub())
    

    Is the same as:

    <SUB>This is SUBSCRIPT text</SUB>
    

    Producing:

    This is SUBSCRIPT text

  • substr(start, length) - Returns the string starting at the "start" index of the string Continuing for the specified length of characters unless the end of the string is found first. The example will return "org".
    mysite = "Comptechdoc.org"
    myname.substring(12, 3)
    
  • substring(start, end) - Returns the string starting at the "start" index of the string and ending at "end" index location, less one. The example will return "org".
    mysite = "Comptechdoc.org"
    myname.substring(12,15)
    
  • sup() - String is displayed using the superscript tags.
    document.write("This is SUPERSCRIPT text".sup())
    

    Is the same as:

    <SUP>This is SUPERSCRIPT text</SUP>
    

    Producing:

    This is SUPERSCRIPT text

  • toLowerCase() - Returns a copy of the string with all characters in lower case.
  • toUpperCase() - Returns a copy of the string with all characters in upper case.