-4

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'));
Not A Bot
  • 2,474
  • 2
  • 16
  • 33
Coder Life
  • 27
  • 5

2 Answers2

2

.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'));
Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
1

You forgot .join("") after reverse;

Shantun Parmar
  • 432
  • 2
  • 13