javascript接受单个参数作为字符串并返回一个字符串 [英] javascript accepts a single parameter as string and returns a string

查看:98
本文介绍了javascript接受单个参数作为字符串并返回一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写一个函数,该函数接受单个参数作为字符串,并返回一个字符串,其中字符串中各个单词的字符被颠倒.换句话说,单词的顺序保持完整,只是构成每个单词的字符应该是相反的.

Write a function that accepts a single parameter as string and returns a string with the characters of individual words within the string being reversed. In other words, the order of words remaining intact, simply the characters that form each word should be reverse

推荐答案

尝试以下操作:

Try this:

var str = 'hi how are you';

var reversedStr = str.split("").reverse().join("");



我在Chrome JavaScript控制台中对此进行了测试.效果很好.

注意:如果是请告诉我紧急"这类问题,则可以用Google搜索"javascript反向字符串"并在10秒内找到答案.



I tested this in my Chrome JavaScript console. works fine.

Note: If it was ''please tell me urgent'' kind of question, you could have Googled ''javascript reverse string'' and found the answer within 10 seconds.


这篇关于javascript接受单个参数作为字符串并返回一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆