📌  相关文章
📜  在不使用内置函数的情况下反转字符串 javascript 中的每个单词 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:05.034000             🧑  作者: Mango

代码示例2
const reverseString = (str = null) => {
let newStr = [];
let string = "";
let reverseStr = "";
for (i = 0; i < str.length; i++) {
   if (str[i] == " ") {
       newStr.push(string);
       string = "";
   } else {
       string += str[i];
   }
 }
if (string) {  
newStr.push(string);
} 
for (i = newStr.length - 1; i >= 0; i--) {
     reverseStr += newStr[i] + " ";
}
return reverseStr;
};
let val = reverseString("My name is mohd jagir");
console.log(val);
//output will be jagir mohd is name My