JavaScript String Object Tutorial

In this Javascript we use the text string "JavaScript String Object" and the str command with various dot syntax to manipulate the actual return of the string's value.

String Command and Dot Syntax Results

 

Code Example
  1. var str=("Grace Murray Hopper");
  2. document.getElementById('codebox').innerHTML += ("string.length() method: this string is " + str.length + " characters long");
  3. document.getElementById('codebox').innerHTML += ("string.toLowerCase() method: this string is " + str.toLowerCase() + " in lowercase");
  4. document.getElementById('codebox').innerHTML += ("string.toUpperCase() method: this string is " + str.toUpperCase() + " in uppercase");
  5. document.getElementById('codebox').innerHTML += ("string.charAt() method: this string is " + str.charAt(4) + " in the line of characters");
  6. document.getElementById('codebox').innerHTML += ("string.indexOf() method: this string is " + str.indexOf('Murray') + " index of");
  7. document.getElementById('codebox').innerHTML += ("string.substring() method: this string is " + str.substring(3,7) + " a substring of the whole string");
  8. document.getElementById('codebox').innerHTML += ("string.lastIndexOf() method: this string is " + str.lastIndexOf('Fred') + " the last index of");
  9. document.getElementById('codebox').innerHTML += ("string.replace() method: this string is " + str.replace('Grace','Jeff') + " replaces Grace with Jeff");