What I'm trying to do here is when item/data isRemove it will adjust the number.
It will adjust the number in noFrom and noTo.
the current sample code just minus 1.
How to make the data like this
[
{noFrom: 1,noTo: 1},
{noFrom: 2,noTo: 2},
{noFrom: 3,noTo: 3},
{noFrom: 4,noTo: 7},
{noFrom: 8,noTo: 8},
{noFrom: 9,noTo: 9},
]
how about that
const items = [
{noFrom: 1,noTo: 1,},
{noFrom: 2,noTo: 2,isRemove: true},
{noFrom: 3,noTo: 3,},
{noFrom: 4,noTo: 4,},
{noFrom: 5,noTo: 5,isRemove: true,},
{noFrom: 6,noTo: 9,},
{noFrom: 10,noTo: 10,},
{noFrom: 11,noTo: 11,},
];
let lt = [...items];
let removeCount = 0;
for(let i of lt) {
i.noFrom -= removeCount;
i.noTo -= removeCount;
if(i.isRemove) {
removeCount++;
}
}
lt = lt.filter(i => !i.isRemove);
console.log(lt);
produces this code:
[
{noFrom: 1,noTo: 1},
{noFrom: 2,noTo: 2},
{noFrom: 3,noTo: 3},
{noFrom: 4,noTo: 7},
{noFrom: 8,noTo: 8},
{noFrom: 9,noTo: 9},
]