Answers for "Switching words in a string using replace"

0

Switching words in a string using replace

let re = /(\w+)\s(\w+)/;
let str = 'John Smith';
let newstr = str.replace(re, '$2, $1');
console.log(newstr);  // Smith, John
Posted by: Guest on September-01-2021

Code answers related to "Switching words in a string using replace"

Code answers related to "Javascript"

Browse Popular Code Answers by Language