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

Your email address will not be published. Required fields are marked *