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

471
Visualizações
How to select api response with a condition angular javascript?

I have an api response that gets me a multiple objects and inside that object I have an array called "employes" ,"employes" has an item called "avis" .

I want to select the object when the value inside of employes>recrutments>avis="accepter" .

all the array inside the object have to get the value "avis"="accepter" to select that object.

If one of the employes has a diffrent value of "avis" then the object is decline.

enter image description here

enter image description here

I tried to map on the response and I used every method of JavaScript

getJuction():void{
  this.getAlloff.getjuction()
  .subscribe(data => {

    console.log(data);
    
    this.test = data.map(function(element:any){
   
      return element.employes.map((employe:any)=>employe.recrutements.avis === 'accepter').every((emel:any) => emel === true ) ;
     
      
      });
      console.log(this.test)
      var test2 = data.filter((employe:any)=>employe);
      console.log(test2)
      
    // var test =data.flat();
    // console.log(test)
    
    

  }, error => console.log(error));

}

This is the result I get.

The only object that has "accepter" for every value gets true

enter image description here

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

0

  this.getAlloff.getjuction()
  .subscribe(data => {
   //this.result some property to store value
    this.result = data.map( (item : any) => {
          return item.employees.filter((item : any)=> {
                 return item.recrutements.alves == 'accepter'
         })
    })
}

try this out if you getting Multiple Object in data

about 4 years ago · Juan Pablo Isaza Relatório

0

I found the solution, I just changed the method from "map" to "filter" method.

This was the previous code:

getJuction():void{
  this.getAlloff.getjuction()
  .subscribe(data => {

    
    this.test = data.map(function(element:any){
   
      return element.employes.map((employe:any)=>employe.recrutements.avis === 'accepter').every((emel:any) => emel === true ) ;
     
      
      });
      
       }, error => console.log(error));

}

This is the new code:

 getJuction():void{
      this.getAlloff.getjuction()
      .subscribe(data => {

        
        this.test = data.filter(function(element:any){
       
          return element.employes.map((employe:any)=>employe.recrutements.avis === 'accepter').every((emel:any) => emel === true ) ;
         
          
          });
          
           }, error => console.log(error));

    }

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