I call the split function passing dash which separate each part of the string
str.split("-").reverse().join("-");
Description of functions used
String.prototype.split()
: The split() method turns a String into an array of strings, by separating the string at each instance of a specified separator string.
const chaine = "Text";
console.log(chaine.split('')); // output ["T", "e", "x", "t"]
Array.prototype.reverse()
: The reverse() method reverses an array in place. The first array element becomes the last, and the last array element becomes the first.
const characters = ["T", "e", "x", "t"];
console.log(characters.reverse()); // output ["t", "x", "e", "T"]
Array.prototype.join()
: The join() method creates and returns a new string by concatenating all of the elements in an array
const reverseCharacters = ["t", "x", "e", "T"];
console.log(reverseCharacters.join('')); // output "txeT"
solved Reverse the String in JavaScript [duplicate]