//more compact way:
"my example text".split("").reverse().join("");
const reverse = str => str.split("").reverse().join("")
const reverse = (string) => {
const newText = string
.split("")
.reverse()
.join("");
return newText
};
console.log(reverse("Hello world"))
//dlrow olleH
function stringReverse(string){
var str = ''
for(const letter of string){
str = letter + str;
}
return str;
}
console.log(stringReverse("Hello World"));
//Output will be
//dlroW olleH
//String Reverse [ String.prototype.polyReverse() ]
String.prototype.polyReverse = function () {
return this.split("").reverse().join("")}
var str = "abc"; console.log(str.polyReverse()) //"cba"
//Object Reverse [ Array.prototype.reverse.call(obj) ]
const obj = {0: 1, 1: 2, 2: 3, length: 3}
Array.prototype.reverse.call(obj)
console.log(obj) // {0: 3, 1: 2, 2: 1, length: 3}
//TypedArray Reverse [ TypedArray.prototype.reverse() ]
const uint8 = new Uint8Array([1, 2, 3])
console.log(uint8.reverse()) //[3,2,1]