How to use split() and join() In Javascript
The split() and join() are two separate inbuild function of JavaScript, split() is used to split a string at particular place and join() is used to join that splited string into one with some argument passed during operation performance.
Example: It describes how we can replace multiple characters in a string using the split() and join() method
// Original String
let str =
'ptlcomt GttksforGttks, ptlcomt gttks';
// Replacing character
let newString =
str.split('p').join('w').split('t').join('e');
// Printing the result
console.log(newString);
Output
welcome w3wiki, welcome geeks
JavaScript Program to Replace Multiple Characters in a String
We are going to learn how we can replace Multiple Characters in a String. We have to replace multiple characters in a string using the inbuilt function or any other method.
Table of Content
- Using replace() method
- Using replaceAll() method
- Using split() and join()
- Using regular expression
- Using reduce()
- Using Map() Method