FileSystemDirectoryHandle: entries() 方法
注意:此功能在 Web Workers 中可用。
FileSystemDirectoryHandle 介面的 entries() 方法會返回一個新的非同步迭代器,用於迭代呼叫該方法的 FileSystemDirectoryHandle 中各項的鍵值對。這些鍵值對的形式是 [key, value] 這樣的陣列。
語法
js
entries()
引數
無。
返回值
一個包含 FileSystemDirectoryHandle 中每一項的鍵值對的新非同步迭代器。
異常
NotAllowedErrorDOMException-
如果控制代碼的
PermissionStatus.state在read模式下不是'granted',則會丟擲此錯誤。 NotFoundErrorDOMException-
如果當前項未找到,則會丟擲此錯誤。
示例
使用 for await...of 迴圈可以簡化迭代過程。
js
const dirHandle = await window.showDirectoryPicker();
for await (const [key, value] of dirHandle.entries()) {
console.log({ key, value });
}
規範
| 規範 |
|---|
| 檔案系統 # api-filesystemdirectoryhandle-asynciterable |
瀏覽器相容性
載入中…