JavaScript String charAt() Method
This method is used whenever we want to Return the first character of a string
for example:
var str = "PRANAV CHHABRA";
var v = str.charAt(0);
Result:
P
Now below is the full example to illustrate charAt() method:
<!DOCTYPE html>
<html>
<body>
<p>Click the result button to display the first character of the string "PRANAV CHHABRA".</p>
<button onclick="myFunction()">Result</button>
<p id="abc"></p>
<script>
function myFunction() {
var str = "PRANAV CHHABRA";
var v = str.charAt(0)
document.getElementById("abc").innerHTML = v;
}
</script>
</body>
</html>
0 Comment(s)