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

116
Views
attribution issues involving for loops

I am trying to remove items from an array. But i have to do it from each item from it. For that, I used a for loop, and ,in the begging of the loop, I try to renovate the array values by using the const seq.

But the sequence array keeps decreasing it's length as the for loop runs. I am trying to remove one item, do some stuff and put it back to the array so I can do the same thing with the next item.

const q = sequence;
for(let i= sequence.length-1; i>=0 ; i--){
        sequence = q;
        sequence.splice(i,1,);
        console.log(sequence);   
           //do some other stuff here

}

output ex:

Input:sequence: [1, 3, 2]

Console Output:[ 1, 3 ]
               [ 1 ]
               []

what i expected: [1, 3]
                 [1, 2]
                 [3,2]
about 4 years ago · Juan Pablo Isaza
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!