Q:

Get output outside the ajax call

I'm using the libraby request for my ajax call, this library give me a response and after I'm using JSON.
I've got a constant id inside and where I'm block is to use this constant outside the request()
I know that I need a promises but I don't understand how to use it ...
const options = {
***
 },
};

request(options, function(error, response, issue) {
 const json = JSON.parse(issue);
 for (let i = 0; i < json.versions.length; i++) {
    const test = json.versions[i].name;
    if (test === version) {
        const id = json.versions[i].id;  //here id
    }
 }
});
console.log(id); // I need to retrieve the const id here but id it's undefined, so how can I specified id 

A:

Try using:
const options = {
***
 },
};
let id;

function getMyBody(options, callback) {
  request(options, function(error, response, issue) {
 const json = JSON.parse(issue);
 for (let i = 0; i < json.versions.length; i++) {
    const test = json.versions[i].name;
    if (test === version) {
        const id = json.versions[i].id;  //here id
        callback(id);
    }
 }
});  
  });
}
getMyBody(options,(id)=>{this.id = id; console.log(id);})

