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

158
Views
How to get index of multiple IDs in response

The following code gets an index of specific ID in response. It works fine when ID is the only one. But now I have 3 IDs. So what to do to get multiple index of multiple IDs?

function getIndex(CategoryID) {
    return response.responseContents.findIndex(
        (obj) => obj.CategoryID === CategoryID,
    );
}

const index = getIndex(CategoryToGetName);
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can do a simple for loop where you populate an array with the matched indexes.

let idxs = [];
for (let i in response.responseContents) {
 if (response.responseContents[i] == CategoryID) idxs.push(parseInt(i));
}
return idxs;
about 4 years ago · Juan Pablo Isaza Report

0

You could do something like:

function getIndex(CategoryID)
{
   return response.responseContents.map((obj, index) => {
       if (obj.CategoryID === CategoryID)
           {
                return index;
           }
   }
}

const index = getIndex(CategoryToGetName);
about 4 years ago · Juan Pablo Isaza Report

0

Please try below code

findIndex(CategoryIDS){
     return response.responseContents.filter((r,index)=>
       if(CategoryIDS.indexOf(r.CategoryID)>-1){
         return index;
       }
     )
}
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!