View result of forEach outside it [closed]

-2

Is there any way the data of forEach can be viewed outside of forEach ?

I need to view the forEach data outside of it, but every time I do this it only returns the last data, not all data. I've already tried using localStorage and the same result.

If it does not, is there any way to do a forEach with two arrays? Could you give examples?

My code:

this.MetaService.CheckOrderGet().subscribe(
              data => {
                const pesquisa = (data as any)
                this.check = JSON.parse(pesquisa._body)            


                this.check.forEach(apielement => {

                  this.fil.forEach(dados=> {            


                    if (apielement.FI == dados.FI) {
                      console.log('Dados iguais ${apielement.FI}');                      
                    }else{
                      console.log('Diferentes ${apielement.FI}');

                    }

                  })                
              }
            )
    
asked by anonymous 20.09.2018 / 17:25

2 answers

1

I do not quite understand your doubt, but this function here makes the comparison between the two arrays, line by line, checking the data at each position if they are the same or different. It begins by scanning the first array and traverses the second array by comparing the indices.

const a = [1, 2, 3, 4, 5, 6, 7];
const b = [5, 4, 3, 1, 2, 5, 6];

a.forEach(function(valor){
    b.forEach(function(v) {
        if(v === valor)
            console.log('iguais');
        else
            console.log('diferentes');
    });
});
    
21.09.2018 / 20:29
0
this.MetaService.CheckOrderGet().subscribe(
data => {
const pesquisa = (data as any)
this.check = JSON.parse(pesquisa._body)            

this.new = [];
for (var key in this.check) {
  if (this.check[key].FI == this.fil[key].FI){
   this.new[] = 'Dados iguais ${this.check[key].FI}';
  }else{
  this.new[] = 'Diferentes ${this.check[key].FI}';
  }
}

);

o new will be out of forech

    
20.09.2018 / 19:49