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

148
Views
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 answers
Answer question

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 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!