How to remove β€œ,” from a string in JavaScript



We are given a main string and a substring, our job is to create a function shedString() that takes in these two arguments and returns a version of the main string which is free of the substring.

For example βˆ’

shedString('12/23/2020', '/');

should return a string βˆ’

'12232020'

Let’s now write the code for this function βˆ’

Example

const shedString = (string, separator) => {
   //we split the string and make it free of separator
   const separatedArray = string.split(separator);
   //we join the separatedArray with empty string
   const separatedString = separatedArray.join("");
   return separatedString;
}
const str = shedString('12/23/2020', '/');
console.log(str);

Output

The output of this code in the console will be βˆ’

12232020
Updated on: 2020-08-19T06:45:08+05:30

166 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements