HaveI have to reverse a string in JavascriptJavaScript and cannot use the built in reverse()reverse() function. It does not seem efficient to have to create two arrays but is there a better way?
function reverseString(str) {
newarr = str.split("");
result = [];
x = newarr.length;
for (i = x; i > -1; i--) {
result.push(newarr[i]);
}
str = result.join("");
return str;
}
reverseString("hello");