Wanted to make reverse string without using the loop I am getting an array
function reverseString(str) {
return str
.split("")
.reverse();
}
console.log(reverseString('coder'));
Wanted to make reverse string without using the loop I am getting an array
function reverseString(str) {
return str
.split("")
.reverse();
}
console.log(reverseString('coder'));
.split()
creates an Array; after doing .reverse()
it's still an Array.
Use Array.prototype.join() to return a String:
function reverseString(str) {
return str
.split("")
.reverse()
.join("");
}
console.log(reverseString('coder'));