JS Built-ins
← Array160 / 226
ArrayArray.prototype.reverseintermediate

Array.prototype.reverse() β€” reverse word order in a sentence

πŸ“– Usage Example
const sentence = 'one two three'
sentence.split(' ').reverse().join(' ')
// β†’ 'three two one'

Use split, reverse, and join to reverse the order of words in a sentence.

Reversing words in a sentence

Split the sentence into words, reverse the word array, then join them back together.

'hello world'.split(' ').reverse().join(' ') // 'world hello'
πŸ’‘ Hints (2)
  • β€’ Split on `' '` (single space) to get an array of words.
  • β€’ Chain: `.split(' ').reverse().join(' ')`.