我正在尝试弄清楚如何在javascript中只迭代列表的特定部分。
在Python中,我是这样做的:
board = range(101)
answer = 92
match = []
low = answer - 2
high = answer + 2
for i in board[low:high + 1]:
    match.append(i)我的问题是,如何在javascript中编写类似的for循环?
发布于 2018-07-20 07:33:38
您可以遍历列表中需要的slice
const board = new Array(101).fill().map((_, i) => i) //this way you can create range of [0..101]
...
board.slice(low, high+1).forEach(i=>{
  match.append(i)
})https://stackoverflow.com/questions/51433064
复制相似问题