
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Reverse all the words of sentence JavaScript
We are required to write a JavaScript function that takes in a string and returns a new string which has all the words reversed from the original string.
For example −
If the original string is −
"Hello World how is it outside"
Then the output should be −
"olleH dlroW woH si ti edistuo"
Now, let's write the code for this function −
Example
const str = 'Hello World how is it outside'; const reverseSentence = str => { const arr = str.split(" "); const reversed = arr.map(el => { return el.split('').reverse().join(""); }); return reversed.join(" "); }; console.log(reverseSentence(str));
Output
The output in the console will be −
olleH dlroW woh si ti edistuo
- Related Articles
- Replace all occurrence of specific words in a sentence based on an array of words in JavaScript
- Python - Generate all possible permutations of words in a Sentence
- Counting number of words in a sentence in JavaScript
- Program to reverse a sentence words stored as character array in C++
- Reverse only the odd length words - JavaScript
- Print all words occurring in a sentence exactly K times
- C# program to remove all duplicates words from a given sentence
- Java program to remove all duplicates words from a given sentence
- Constructing a sentence based on array of words and punctuations using JavaScript
- Arranging words by their length in a sentence in JavaScript
- Finding n most frequent words from a sentence in JavaScript
- Split the sentence into words in C++
- How to split sentence into blocks of fixed length without breaking words in JavaScript
- Generate all combinations of supplied words in JavaScript
- Reverse the words in the string that have an odd number of characters in JavaScript

Advertisements