Search code examples
node.jsuuid

How to remove dashes in UUID with nodejs?


I'm trying to remove the dashes in the UUID by using the replace function on NodeJS but unsuccessful as it always returns with dashes.

const { v4: uuidv4 } = require('uuid');

const uuid = uuidv4().toString()

console.log(uuid.replace("-",""))

The code above is what I'm trying to do to remove the dashes. Thanks


Solution

  • function replace only try 1 times

    you can replace all '-' use RegExp like this:

    uuid.replace(/-/gi, '');