Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

reverse every word in a string javascript

function reverseWords(str) {
  const allWords = str.split(" ")
  return allWords.map(item => item.split("").reverse().join("")).join(" ")
}
Comment

reverse each word in string javascript without using inbuilt function

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
Comment

PREVIOUS NEXT
Code Example
Javascript :: link to website electron 
Javascript :: Comment intégrer font awesome et bootstrap dans angular 13 
Javascript :: typeof javascript 
Javascript :: convert a date into timestamp in javascript 
Javascript :: uppercase first letter javascript 
Javascript :: Deploying Node.js Apps on Heroku 
Javascript :: move item to end of array for of 
Javascript :: reactjs firebase timestamp to date 
Javascript :: multi ternary operation in javascript 
Javascript :: jquery get custom attribute 
Javascript :: next js react image upload 
Javascript :: equality operator javascript 
Javascript :: pm2 logs on same console 
Javascript :: how to include js file in react 
Javascript :: reduce object to array javascript 
Javascript :: blob to text javascript 
Javascript :: js change h 
Javascript :: Implement stack as an abstract data type using singly linked list and use this ADT for conversion of infix expression to postfix, prefix and evaluation of postfix and prefix expression. 
Javascript :: string into json javascript 
Javascript :: radio button checked jquery 
Javascript :: react radio button checked not working 
Javascript :: use $ instead of jQuery 
Javascript :: get duplicate value javascript 
Javascript :: javascript get distance between months 
Javascript :: next js custom document 
Javascript :: ndjson to json javascript 
Javascript :: create secure jwt secret key using node crypto 
Javascript :: anjular js 
Javascript :: all redux reuired packages 
Javascript :: ajax is not a function 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =