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

0

101
Views
Cómo obtener el índice de múltiples ID en respuesta

El siguiente código obtiene un índice de ID específico como respuesta. Funciona bien cuando ID es el único. Pero ahora tengo 3 identificaciones. Entonces, ¿qué hacer para obtener múltiples índices de múltiples ID?

 function getIndex(CategoryID) { return response.responseContents.findIndex( (obj) => obj.CategoryID === CategoryID, ); } const index = getIndex(CategoryToGetName);
almost 3 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Puede hacer un bucle for simple en el que complete una matriz con los índices coincidentes.

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

0

Podrías hacer algo como:

 function getIndex(CategoryID) { return response.responseContents.map((obj, index) => { if (obj.CategoryID === CategoryID) { return index; } } } const index = getIndex(CategoryToGetName);
almost 3 years ago · Juan Pablo Isaza Report

0

Por favor intente debajo del código

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

Recommend me some offers
I have an error