0

I want to store api response inside an array so that I can search whether a particular email_address is already present or not

var emailArr = [];
  request(options, function (err, response, body) {
    var jsonBody = JSON.parse(body);
 
    if (err) {
      console.log(err);
    } else {
      for (var i = 0; i < jsonBody.members.length; i++) {
        emailArr.push(jsonBody.members[i].email_address);
      }
      console.log(emailArr) // values are present
    }
  });
  console.log(emailArr); // empty array

The email array is consoling empty outside the request callback function but showing values inside, please tell me what can be the better solution

HarshV
  • 1
  • 2

0 Answers0