I’m trying to reverse an input string
var oneway = document.getElementById('input_field').value();
var backway = oneway.reverse();
but firebug is telling me that oneway.reverse() is not a function. Any ideas?
Thank you
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
reverse()is a method of array instances. It won’t directly work on a string. You should first split the characters of the string into an array, reverse the array and then join back into a string:Update
The method above is only safe for “regular” strings. Please see comment by Mathias Bynens below and also his answer for a safe reverse method.