<html>
<head> <title>Reverse String Example</title>
</head>
<body>
<input type="text" id="inputString">
<button onclick="reverse()">Reverse</button>
<script>
function reverse()
{
var a = document.getElementById("inputString").value;
var reversed = a.split("").reverse().join("");
document.write(reversed);
}
</script>
</body>
</html>
note: In this approach, we're splitting the string into an array of individual characters using the
split("")
method, then reversing the order of the array using the reverse()
method, and finally joining the characters back into a string using the join("")
method with an empty string as the separator. This produces the reversed string as the final output. <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4371523905678056"
crossorigin="anonymous"></script>
No comments:
Post a Comment