JSFiddle - React, Tailwind, and code Playground

by Pritesh Patel

JavaScript

String.prototype.reverseWord = function() {
  var words = this.split(" ").reverse(); // Split the sentence into an array of words and reverse it
  var string = "";
  for (let word in words)
    string += (word > 0 ? " " : "") + words[word]; // Concatenate each word to the output and add spaces where required
  return string;
}
console.log(reverseWord("hello"));