JSFiddle - React, Tailwind, and code Playground
by Vladymyr Shevchuk
JavaScript
const obj = {
0: [0, 5],
1: [0, 6],
2: [0, 7],
3: [2, 0], // will be skiped
4: [2, 2],
5: [2, 3]
};
/* const result = {
0: {
0: [0, 5],
1: [0, 6],
2: [0, 7],
},
1: {
4: [2, 2],
5: [2, 3]
}
}; */
const result = {};
const mainArray = Object.entries(obj);
for (const [index, arr] of mainArray) {
const [firstElement] = arr;
const nextArr = mainArray[index + 1];
console.error('arr', arr);
console.error('nextArr', nextArr);
const [secondElement] = nextArr;
console.error('firstElement', firstElement);
console.error('secondElement', secondElement);
}