Skip to content

Reverse a string in one line JavaScript | HTML example code

  • by

There is no single method to Reverse a string in one line JavaScript but you can arrange methods in a single line. Use split, reverse, and join methods for it.

Reverse a string in one line JavaScript Example

HTML example code: create a function for it you can use only return value code if want one-time use.

string.split("").reverse().join("");

Complete code

<!DOCTYPE HTML> 
<html> 

<body> 

	<script>
		
		function reverse(s){
			return s.split("").reverse().join("");
		}
		console.log(reverse("Hello World"));

	</script>
</body> 
</html>	

Output:

Reverse a string in one line JavaScript

Do comment if you have any doubts and suggestions on this topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading