Iterate an array as a pair (current, next) in JavaScript

前端 未结 13 974
情话喂你
情话喂你 2020-12-09 09:06

In the question Iterate a list as pair (current, next) in Python, the OP is interested in iterating a Python list as a series of current, next pairs. I have th

13条回答
  •  死守一世寂寞
    2020-12-09 09:42

    Lodash does have a method that allows you to do this: https://lodash.com/docs#chunk

    _.chunk(array, 2).forEach(function(pair) {
      var first = pair[0];
      var next = pair[1];
      console.log(first, next)
    })
    

提交回复
热议问题