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

242
Visualizações
How to pass values from an array to filter clause while hitting a url

I have the below student values in an array

var arr=['sam','peter','alex']

Now I am hitting an endpoint where in I need to filter out the values based on the student names as follows.

***************/$format=json&$filter=name eq 'sam' or name eq 'peter' or name eq 'alex'&$select=id,address

getData is a custom function to connect to db and performs odata call Below is the implementation I have used.

getData([
                    `/student_details`,
                    `?$format=json`,
                    `&$filter=name eq '${arr}'`,
                   `&$select=id,address`
                ])

the length of the names array is not constant and it keeps varying. The above piece of code doesn't work and instead the url is framed as

***************/$format=json&$filter=name eq 'sam,peter,alex'&$select=id,address

How do I correct this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Just use declare a variable query that later on you will use in your getData function:

var arr=['sam','peter','alex'];

var query = arr.map(e => `name eq "${e}" `).join('or ');

console.log(query);

getData([
    `/student_details`,
    `?$format=json`,
    `&$filter='${query}'`,
    `&$select=id,address`
]);

`

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