As long as you're dealing with simple ASCII characters, and you're happy to use built-in functions, this will work:
(只要您要处理简单的ASCII字符,并且很高兴使用内置函数,就可以使用:)
function reverse(s){
return s.split("").reverse().join("");
}
If you need a solution that supports UTF-16 or other multi-byte characters, be aware that this function will give invalid unicode strings, or valid strings that look funny.
(如果您需要支持UTF-16或其他多字节字符的解决方案,请注意此函数将提供无效的unicode字符串或看起来很有趣的有效字符串。)
You might want to consider this answer instead .(您可能需要考虑此答案 。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…