Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

reverse a word javascript

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

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 :: react prevent component from update once mounted 
Javascript :: how to capture a thumbnail from a video 
Javascript :: keydown events 
Javascript :: how to add property to object in javascript 
Javascript :: lodash remove null from object 
Javascript :: antd datepicker set min max 
Javascript :: python pretty print json command line 
Javascript :: base64 to blob 
Javascript :: convert a string to object javascript 
Javascript :: mdn rest 
Javascript :: js isset variable 
Javascript :: switch in react 
Javascript :: (Unauthorized) not authorized on admin to execute command 
Javascript :: reload data in datatable 
Javascript :: array map arrow function 
Javascript :: click unbind 
Javascript :: js string count 
Javascript :: disabled radio button 
Javascript :: iife javascript 
Javascript :: react google map 
Javascript :: toarray javascript 
Javascript :: array js fill 
Javascript :: javascript extract date from string 
Javascript :: change image src using jquery 
Javascript :: preloader js code 
Javascript :: how to download file from link in react 
Javascript :: javascript check for null variables 
Javascript :: javascript .foreach 
Javascript :: vscode rest api extention POST method 
Javascript :: javascript pre increment and post increment 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =