[Javascript] Creating an Iterator from an Array
JavaScript from Array an Iterator creating
2023-09-14 09:00:48 时间
Every Array has a function which you can use to create an iterator. This function can only be accessed by using the Symbol.iterator
as a key on the Array. Once you have created your iterator, you can use it to iterate through each value of the Array using .next
or a for loop
.
const abcs = ["A", "B", "C"] const createIterator = abcs[Symbol.iterator].bind(abcs) const iterator = createIterator() for (const i of iterator) { console.log(i) } for (const i of createIterator()) { console.log(i) }
相关文章
- Win10系列:JavaScript页内导航
- [Javascript] Hide Properties from Showing Up in "for ... in" Loops in JavaScript
- [Javascript] Yield an Array, String, or Any Iterable from a Generator (yield*)
- [Javascript] Creating an Iterator from an Array
- [Cypress] install, configure, and script Cypress for JavaScript web applications -- part4
- [Functional Programming] Draw Items from One JavaScript Array to Another using a Pair ADT
- [Rust] Pass a JavaScript Function to WebAssembly and Invoke it from Rust
- [Javascript] Highlights from IO18 Javascript new features
- [Javascript] Case insensitive sorting for string arrays
- [Javascript] Broadcaster + Operator + Listener pattern -- 6. Create a Buffer to Pair Values Together with Zip
- [Javascript Crocks] Recover from a Nothing with the `alt` method
- [WASM] Call a JavaScript Function from WebAssembly
- AngularJs - Javascript MVC 框架
- JSON说明及使用,javascript,java如何解析及转化json
- JavaScript中的排他算法实现按钮单选
- 19 个常用的 JavaScript 简写方法
- javascript反混淆之packed混淆