我有
str = "it is a boy"
我希望我的控制台像"boy a is it"一样反向打印str。我试过这个:
"boy a is it"
str
console.log(str.split(' ').reverse().join(' ')); // yob a si ti
w3nuxt5m1#
var revStr = 'it is a boy'.split(' ').reverse().join(' ');
mpgws1up2#
var reverseWords = function(s) { let strArr=s.substring(s).split(" "); let reverseArr=[]; strArr.forEach(item=>{ let reverseItem=item.split('').reverse(); reverseArr.push(reverseItem.join("")) }) return reverseArr.join(" ") }; console.log(reverseWords("Let's connect"))
2条答案
按热度按时间w3nuxt5m1#
mpgws1up2#