let rowsArrT = [];
let currentRow;
rowsEle = ['row1', 'row2', 'row3', 'row4']
function setRows(rows) {
rows.forEach((row, ind) => {
rowsArrT.push({ row, id: ind, next: false, notes: 0 })
});
rowsArrT[0].next = true;
localStorage.setItem('TestRows', JSON.stringify(rowsArr));
}
function getCurrentRow() {
rowsArrT.map((row, ind) => {
if (row.next === true) {
console.log(row)
currentRow = row;
rowsArrT[ind].next = false;
if (ind !== rowsArrT.length - 1) {
rowsArrT[ind + 1].next = true;
} else {
rowsArrT[0].next = true;
}
}
})
}
setRows(rowsEle)
window.addEventListener('click', () => {
getCurrentRow()
console.log('-----After generate-----')
console.log(currentRow)
console.log(rowsArrT)
})
when I loop through this array and change its properties depending on some conditions , all the array's element property getting change to the condition that I added!, but when I check again outside the loop, the current element got stuck into the fourth row, It should change with each event
I tried to loop through this loop items, and change its 'next' property in sequence, but I still get stuck in the row 4, and loop don't work as expected