簡體   English   中英

將數組轉換為 ES6 可迭代

[英]Convert Array to ES6 Iterable

我找到了答案: Convert ES6 Iterable to Array

但我正在尋找相反的情況:

如何將['something', 'another thing']類的數組轉換為 ES6 Iterable?

Array已經是 ES6 可迭代對象。

“可迭代”是許多不同類型的對象可以擁有的能力,而數組具有內置的能力(從 ES6 開始)。

例如,您可以直接使用迭代器功能,例如:

for (let item of ['something', 'another thing']) {
     console.log(item);
}

或者,您可以使用以下命令直接獲取迭代器:

const myIterator = ['something', 'another thing'].entries();
console.log(myIterator.next().value);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM