Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

176
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda