Crypto: phương thức randomUUID()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2022.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is available in Web Workers.

Phương thức randomUUID() của giao diện Crypto được dùng để tạo một UUID v4 bằng bộ sinh số ngẫu nhiên an toàn về mặt mật mã.

Cú pháp

js
randomUUID()

Tham số

Không có.

Giá trị trả về

Một chuỗi chứa một UUID v4 được tạo ngẫu nhiên với độ dài 36 ký tự.

Ví dụ

js
/* Assuming that self.crypto.randomUUID() is available */

let uuid = self.crypto.randomUUID();
console.log(uuid); // for example "36b8f84d-df4e-4d49-b662-bcde71a8764f"

Thông số kỹ thuật

Specification
Web Cryptography Level 2
# Crypto-method-randomUUID

Tương thích trình duyệt

Xem thêm