How to use JavaScript charAt

In this article we will discuss about how to charAt() Method in JavaScript.
  • 2405

This is the most important method of the string in JavaScript. This method gives the character of the string from the specified index. The charAt() method takes index as a parameter and returns the particular character placed at specified index. If the index will be 0 then this method will return first character of the string and so on.

JavaScript Code:

<html>

<head>

    <title>JavaScript String charAt() Method</title>

</head>

<body>

    <script type="text/javascript">

        var st = new String("Health is Wealth");

        document.writeln("str.charAt(0) is:" + st.charAt(0));

        document.writeln("<br />st.charAt(1) is:" + st.charAt(1));

        document.writeln("<br />st.charAt(2) is:" + st.charAt(2));

        document.writeln("<br />st.charAt(3) is:" + st.charAt(3));

        document.writeln("<br />st.charAt(4) is:" + st.charAt(4));

        document.writeln("<br />st.charAt(5) is:" + st.charAt(5));

        document.writeln("<br />st.charAt(5) is:" + st.charAt(6));

        document.writeln("<br />st.charAt(5) is:" + st.charAt(7));

        document.writeln("<br />st.charAt(5) is:" + st.charAt(8));

    </script>

</body>

</html>

Output:
charat.jpg

Ask Your Question 

Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.