我有 1 个像这样的不可变列表
const list = new List([
new Map({ title: 'first', complete: true }),
new Map({ title: 'second',complete: false }),
])
当我使用
list.map((value,index) => {
//HOW TO GET VALUE OF NEXT ELEMENT IN HERE ?
})
最佳答案
你可以这样做
list.map((value,index) => {
const next = list.get(index + 1);
// next will be undefined when the value is last one in the list (and index + 1) is out of bounds because of that
})
只是为了澄清这个例子使用了一个事实,即不可变列表是 Collection.Indexed 的后代,它有 get(index) method
关于javascript - 使用.map时如何获取不可变列表中的下一个元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54460778/