如何使用nodejs删除UUID中的破折号?

How to remove dashes in UUID with nodejs?

我正在尝试通过在 NodeJS 上使用替换功能来删除 UUID 中的破折号,但没有成功,因为它总是 returns 带有破折号。

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

const uuid = uuidv4().toString()

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

上面的代码是我试图删除破折号的代码。谢谢

函数替换只尝试1次

您可以像这样使用 RegExp 替换所有“-”:

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