How to use Split() and Join() Method In Javascript
We can split up strings of text with the JavaScript split() method and join() method to join strings using the replace characters with the join method.
Syntax:
string.split('.').join(' ');
Example: Here we are replacing the dots(.) with space( ) using split and join.
// Assigning a string
let str = "A.Computer.Science.portal";
// Calling split(), join() function
let newStr = str.split(".").join(" ");
// Printing original string
console.log("String 1: " + str);
// Printing replaced string
console.log("String 2: " + newStr);
Output
String 1: A.Computer.Science.portal String 2: A Computer Science portal
How to replace all dots in a string using JavaScript ?
We will replace all dots in a string using JavaScript. There are multiple approaches to manipulating a string in JavaScript.
Table of Content
- Using JavaScript replace() Method
- Using JavaScript Split() and Join() Method
- Using JavaSccript reduce() Method and spread operator
- Using JavaScript replaceAll() Method
- Using JavaScript for loop
- Using JavaScript map() Method on Arrays
Contact Us