Prev Demo
Returning The Different Characters Of String From Start& End
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>charAt() method for different characters</h1> <p>Click on the "Button" for returning the characters of a string "SN ITFunda Service LLP" from Start & End.</p> <input type="button" value="Button" onclick="Function()"/> <p id="myId"></p> <script> function Function() { var a = "SN ITFunda Service LLP"; var res = "2nd character from Start:" + a.charAt(1) + "</br>" + "2nd character from End:" + a.charAt(a.length - 2) + "</br>" + "3rd character from Start:" + a.charAt(2) + "</br>" + "3rd character from End:" + a.charAt(a.length - 3); document.getElementById("myId").innerHTML = res; } </script> <p><strong>Note:</strong> The 3rd character from start in the string is space, so the the 3rd character is showing emplty value in the output.</p> </body> </html>
Note: We DO NOT save your trial code in our database.
Output