-1

Let's suppose I have a variable

name = 'product with 10/150 mg'

How can I remove the '/' from the variable name using string functions via node.js

(Variable could have multiple '/' so is there a way to remove the value of all '/' in string?)

Can I do something like name.replace() ?

Any help is much appreciated.

Tekky
  • 89
  • 1
  • 9
  • `name.replace(/\//g,'')` there is also [replaceAll](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll), but it's new and support isn't great yet – user120242 Jul 06 '20 at 03:07
  • Indeed, your code above helps. g stands for global identifier, meaning all occurrences. Thank you. – Tekky Jul 06 '20 at 03:21

1 Answers1

1

You can replace / with regex ex:

let name  = 'product with 10/150 mg, product with 30/250 mg, product with 40/650 mg, product with 10/150 mg, product with 20/450 mg';
let result = name.replace(/(\/)/g, ''); 
console.log(result);
faif
  • 26
  • 3