• Jobs
  • About Us
  • Jobs
    • Home
    • Jobs
    • Courses and challenges
  • Businesses
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

112
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);
over 3 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;
over 3 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);
over 3 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;
       }
     )
}
over 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Show me some job opportunities
There's an error!