我有一个将数组转换为对象的问题。
const data = [0, 1, 2, 3, 4, 5];
const arr = data.map((element, idx) => {
return {
f: element,
s: arr[idx + 1],
};
});
当然,arr
是[{f: 0, s: 1}, {f: 1, s: 2}, ...]
,但我想将map
的指数增加2.结果将是这样的:
arr = [{ f: 0, s: 1}, { f: 2, s: 3 }, ...]
有没有办法使用像map
这样的方法来制作结果?