Crypto.randomUUID()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
语法
js
randomUUID()
参数
无。
返回值
包含随机生成的、长度为 36 字符的第四版 UUID 字符串。
示例
js
/* 假定 self.crypto.randomUUID() 可用 */
let uuid = self.crypto.randomUUID();
console.log(uuid); // 例如 "36b8f84d-df4e-4d49-b662-bcde71a8764f"
规范
Specification |
---|
Web Cryptography API # Crypto-method-randomUUID |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
randomUUID() |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
参见
Web Crypto API
Crypto.getRandomValues
,用于获取任意个安全的随机字节的来源。