Reverse String In Javascript
<html> <title>Reverse a string in javascript</title> <body> <center><br> <label>Enter Any String:</label> <input type="text" id="str"> <button type="button" id="btn" onclick="revString()"> Reverse String</button><br> <hr> <h2 style="color:green" id="orgString"></h2> <h2 style="color:green" id="revString"></h2> </center> </body> <script type="text/javascript"> function revString() { let str = document.getElementById('str').value; let revString = ''; document.getElementById('orgString').innerHTML = 'Original String: '+str; for (var i = str.length - 1; i >= 0; i--) { revString+= str[i]; } document.getElementById('revString').innerHTML = 'Reverse String: '+revString; } </script> </html>
Capitalize The First Letter In
const str = 'string Program In Javascript'; const arr = str.split(" "); for (var i = 0; i < arr.length; i++) { arr[i] = arr[i].charAt(0).toUpperCase() + arr[i].slice(1); } const str2 = arr.join(" "); console.log(str2);