jeudi 3 juin 2021

can't fetch data outside of if condition using javascript / node js

is there any possibility i can return value which is return inside like this

let data=[];

object.map((value)=>{
 if(some condition){
  // 1st if condition

   if(some condition){
    //  2nd if condition

     if(some condition){
       // 3rd if condition

       if(some condition){
         //4th if condition
          data.push(something);
        }
      }
   }
 }
}

console.log(data);

Its showing me empty outside the map function as i am pushing values inside the data

  • is there any chances i can get data outside too

or is there any possibility i can return value and use like this

let data=[];

data = object.map((value)=>{
 if(some condition){
  // 1st if condition

   if(some condition){
    //  2nd if condition

     if(some condition){
       // 3rd if condition

       if(some condition){
         //4th if condition
          return (something)
        }
      }
   }
 }
}

console.log(data);

Aucun commentaire:

Enregistrer un commentaire