I'm currently working on a logic that involves looping and logging custom starting point indexes based on specific conditions. For instance, if the current index is not 0, the count will increment.
Here is a sample array data:
const data = [
{ type:'yes',start:1 }, //count index starting point
{ type:'yes',start:1 },
{ type:'no',start:0 }, //skip
{ type:'no',start:0 }, //skip
{ type:'yes',start:5 }, //new index starting point
{ type:'yes',start:5 },
{ type:'no',start:0 }, //skip
{ type:'yes',start:5 }, //new index starting point
{ type:'yes',start:5 },
{ type:'no',start:0 }, //skip
{ type:'yes',start:10 },//new index starting point
{ type:'yes',start:10 },
{ type:'yes',start:10 },
]
If the loop is executed like this:
for(var i = 0; i < data.length ; i++){
// code here
console.log( **newindex** )
}
The expected output for newindex would be:
1,2,0,0,5,6,0,5,6,0,10,11,12
Appreciate any help with solving this issue. Thank you!