Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
spliting of array in javascript

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!