The String object provides us some functionality to manipulate string according to requirement. We can use java script string function to concatenate to strings, to convert it in lower case and upper case, to find out substring and convert it to uppercase and lowercase. In this demonstration I will tell you a brief description about string function in java script.

Method and Property:
  •  length  :  length property is used to find out the length of any string in java script.
  •  toUpperCase()  :  toUpperCase() method is used to convert string in upper case letter.
  •  toLowerCase()  :  toLowerCase() method is used to convert string in lower case letter.
  •  charAt(n)  :  caharAt(n) function is used to find out character at nth position in string where n is an integer value.
  •  substring(startIndex , endIndex )  :  substring() method is used to find out a substring in a given string. We can use startIndex and endIndex value to find out it.
An example which demonstrate use of string object in Java Script
<!DOCTYPE html  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "">
<html xmlns="">
    <script type="text/javascript">
        function stringFunction() {
            var str = "John Corner";
            document.write("Length of the string is  :  " + str.length + "<br />");
            document.write("Upper case letter of the string is  :  " + str.toUpperCase() + "<br />");
            document.write("Lower case letter of the string is  :  " + str.toLowerCase() + "<br />");
            document.write("Value of Position of third character in str string is  :  " + str.charAt(3) + "<br />");
            document.write("Value from second position to fifth position is   :  " + str.substring(2, 5) + "<br />");
    <input type="button" value="Click this to view message" onclick="stringFunction()" />
Output of the following code snippet is as follows

String Object in Java Script

When user clicks this button then he gets output.

String Object in Java Script

  Modified On Mar-22-2018 07:06:17 AM

Leave Comment