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

167
Views
How to rearrange number or reset the number

What I'm trying to do here is when item/data isRemove it will adjust the number.

It will adjust the number in noFrom and noTo.

the current sample code just minus 1.

How to make the data like this

  [
          {noFrom: 1,noTo: 1},
          {noFrom: 2,noTo: 2},
          {noFrom: 3,noTo: 3},
          {noFrom: 4,noTo: 7},
          {noFrom: 8,noTo: 8},
          {noFrom: 9,noTo: 9},
        ]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

how about that


const items = [
      {noFrom: 1,noTo: 1,},
      {noFrom: 2,noTo: 2,isRemove: true},
      {noFrom: 3,noTo: 3,},
      {noFrom: 4,noTo: 4,},
      {noFrom: 5,noTo: 5,isRemove: true,},
      {noFrom: 6,noTo: 9,},
      {noFrom: 10,noTo: 10,},
      {noFrom: 11,noTo: 11,},
    ];

let lt = [...items];
let removeCount = 0;

for(let i of lt) {
    i.noFrom -= removeCount;
    i.noTo -= removeCount;
  if(i.isRemove) {
    removeCount++;
  }
}

lt = lt.filter(i => !i.isRemove);

console.log(lt);

produces this code:

  [
          {noFrom: 1,noTo: 1},
          {noFrom: 2,noTo: 2},
          {noFrom: 3,noTo: 3},
          {noFrom: 4,noTo: 7},
          {noFrom: 8,noTo: 8},
          {noFrom: 9,noTo: 9},
        ]
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!