Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda