Reverse a string in one line JavaScript | HTML example code

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 method for it.

Reverse a string in one line JavaScript Example

HTML example code: crated 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.