Search This Blog

2023/07/25

How to reverse each word in sentence

 var sentence = "Welcome to this Javascript Guide!";

var splitted = sentence.trim().split(/\s+/)

var reversed = splitted.map((word)=>{
return word.split("").reverse().join("")
})

var reversedSentence = reversed.join(" ")

console.log(reversedSentence)

output:
emocleW ot siht tpircsavaJ !ediuG

No comments:

Post a Comment