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

154
Vistas
set back value after for loop is completed

I've have following code with a problem.

After clicking my button in my template my counter will be incremented. Now I want to check if my counter is higher, lower or equal to a length of an array.

After doing my for-loops I want to set my counter back to zero.

I've tried with return this.counter = 0 - but this didn't work.

Thanks in advance for helping me out!

methods: {
  if(this.counter > this.lengthArray) { 
    for(let i = this.lengthArray; i <= this.counter; i++) {
      //Do some code
    }
  } else if (this.lengthArray > this.counter) {
    for(let i = 1; i <= this.counter; i++) {
      //Do some code as well
    }
  } else if (counter == 0) {
    //Process another code
  }
},

data() {
  return {
    counter: 0
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You don't want the method to return the value this.counter = 0.

Setting this.counter = 0 after your last condition should work. Nothing should return or break the loops.

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