0

I am not able to return the value of this variable someobj. Any thoughts much appreciated.

getSomeObj: function () {
               let arr1 = ["abc", "def", "efh", "xys", "xus"]; 
               someobj = {};
               arr1.map((type) =>{
                // Gets the value from a promise as an array
                   this.getValuesOfSomeObj(type).then(function(vals){
                               (vals.map((val) =>{
                                   someobj[val.name] = val.name;
                                   someobj[val.title] = val.title; //I am getting value here
                             }));
                   });
               });
               return someobj; //I am not getting it here
           } 
Siva
  • 21
  • 6
  • this.getValuesOfSomeObj(type).then((vals) => { use arrow function like this. – Sagar Rana Magar Jun 12 '20 at 11:49
  • 2
    Also relevant: [Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference](https://stackoverflow.com/questions/23667086/why-is-my-variable-unaltered-after-i-modify-it-inside-of-a-function-asynchron) – VLAZ Jun 12 '20 at 11:53
  • @VLAZ- the function ```getValuesOfSomeObj returns a promise. I am just trying to consume it. – Siva Jun 12 '20 at 12:40
  • And you should do it *asynchronously*. It's not possible to turn async code into synchronous one. – VLAZ Jun 12 '20 at 12:41
  • @VLAZ - You are correct. – Siva Jun 12 '20 at 17:35

0 Answers0