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

93
Views
Loop through some results to find a path and push it to an array

I need to create a loop to search into some results to find a path and push it into an array but the way I wrote the loop, it searches only the first position, the [0].

How do I loop all of results positions in order to extract the path from all of them?

For better understanding, please check the image and the code below: structure

The code so far looks like:

let results = data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results;

//loop on each results
results[0].Cells.results.forEach(el => {
  let filePath = el.value;
  let fileName = filePath.substring(filePath.lastIndexOf('/') + 1, filePath.length);

  // push to array
 pathResults.push(fileName);
});

Thanks in advance for any suggestions!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

const pathList = data
  .d.query
  .PrimaryQueryResult
  .RelevantResults
  .Table.Rows
  .results
  .reduce((list, { Cells }) => {

    const cellPathItem = Cells
      .results.find(({ Key }) => Key === 'Path');

    if (cellPathItem) {
      list.push(
        cellPathItem.Value.substring(
          cellPathItem.Value.lastIndexOf('/')
        )
      );
    }
    return list;

  }, []);

"Thanks for your sophisticated solution! Could you please show me an approach based more on my existing code?"

const pathList = [];

data.d.query
  .PrimaryQueryResult
  .RelevantResults
  .Table.Rows
  .results
  .forEach(rowItem => {

    const cellPathItem = rowItem.Cells
      .results.find(cellItem => cellItem.Key === 'Path');

    if (cellPathItem) {
      pathList.push(
        cellPathItem.Value.substring(
          cellPathItem.Value.lastIndexOf('/')
        )
      );
    }
  });
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!