Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有.replace(' ', ', ')
.replace(' ', ', ')
我想要的是:
Hanks, Tom
我得到的是:
Hanks,Tom
你怎么做到这一点?
输入字符串是汤姆汉克斯。
我想要汉克斯,汤姆
您可以将字符串拆分为数组并重新排序位。
var str = "Tom Hanks"; var arr = str.split(' '); console.log(arr[0] + ', ' + arr[1]);