Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

100
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda