JavaScript Iterator Class

后端 未结 7 1346
挽巷
挽巷 2020-12-29 07:55

Do you know a JavaScript library that implements a generic Iterator class for collections (be it Arrays or some abstract Enumerable) with a full set of features, like the Go

7条回答
  •  一整个雨季
    2020-12-29 08:07

    Since this hasn't been mention yet arrays have higher-order functions built in.

    Map works like iterator that can only do a single pass.

    [1,2,3,4,5].map( function(input){ console.log(input); } );
    

    This code passes each element in the list into a function, in this case its a simple printer.

    1
    2
    3
    4
    5
    

提交回复
热议问题