How To Use String Object charAt in Java Script

In this article I am going to explain about String Object charAt In JavaScript.
  • 1743

Use charAt() method in JavaScript

The charAt() method returns a string value on the specified index.

The index will be start 0, like(0,1,2).

All browsers support string object charAt() method.

Syntax

string.charAt(index)

Example

<!DOCTYPE html>

<html>

<body style ="background-color:Red">

 

<p id="demo">Display the third character of a string.</p>

 

<button onclick="myFunction()">Click here</button>

 

<script type="text/javascript">

    function myFunction()

     {

        var str = "Welcome";

        document.getElementById("demo").innerHTML = str.charAt(0);

    }

</script>

</body>

</html>

Output1

 op1.jpg

Output2

 op2.jpg

Further Readings

You may also want to read these related articles :here

Ask Your Question 

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

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.