Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error .split("").reverse() not a function [duplicate]

    str = prompt("enter a string");
rev = str.split("").join("").reverse();
console.log(rev);

Guys, I am trying to reverse an array using the above code but I am getting an error stating "Type error .reverse() .split("") and .join("") is not a function.

Please help.

like image 587
Utkarsh gaur Avatar asked Sep 30 '25 09:09

Utkarsh gaur


1 Answers

Javascript strings have no reverse function. You'll have to reverse the array before joining it together into a string:

const str = 'abcde';
const res = str.split('').reverse().join('');
console.log(res);
like image 94
CertainPerformance Avatar answered Oct 02 '25 06:10

CertainPerformance



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!