I have an array which consists of many elements..And there is an html flag which will be raised by the user. Whenever the user raises then the array should split at that point..The user can raise multiple times.If the user does not raise any flag then there should not be any split it should return the initial array.This is the code I wrote when flag is raised.I split the array and push the split array into another one.
flag is an html element..and items is the array that have products. So the problem is if user doesnnot raise any flag..then how we can get the initial array...I need the help in logic.
Use continue when there is no flag:
const Arr = []
const lastIndex = 0
const finalarr = []
for (let i = 0; i < this.items.length; i++) {
if (this.items[i].flag) {
const Split = this.item.slice(lastIndex, i)
Arr.push(Split)
lastIndex = i
finalarr = this.items.slice(i)
}
else continue
}
Arr.push(finalarr)