const str = "I like you,but you don't know,I'm sad." function strReverse(str) { const strList = str.split(',').reverse() strList.forEach((item, index) => { const itemList = item.split(' ') itemList.forEach((iitem, iindex) => { const i = iitem.search(/['.]/) if (i >= 0) { itemList[iindex] = iitem.substring(i + 1, iitem.length) + iitem[i] + iitem.substring(0, i) } }) strList[index] = itemList.reverse().join(' ') }) return strList.join(',') } console.log(strReverse(str))
标签:iitem,const,字符,单词,substring,itemList,str,字符串,strList From: https://www.cnblogs.com/angia/p/16735241.html