I use FACEIT API to get 5 nicknames from a certain match. I want to use that 5 nicknames and store them inside players array and then reuse it to make 5 new url-s that are going to allow me to get more information for each player. Problem is that after I push nicknames to players array I only get undefined.
var express = require("express");
var app = express();
var request = require('request');
var players = [];
var headers = {
    'Accept': 'application/json',
    'Authorization': 'Bearer <my API code which I don't want to display>'
};
var options = {
    url: 'https://open.faceit.com/data/v4/matches/cdc61c3b-2f9b-4c92-a2c9-ea1cfb54eb51',
    headers: headers
};
request(options, function (error, response, body) {
    if (!error && response.statusCode == 200) {
        var parsedBody = JSON.parse(body);
        for (var i = 0; i < 5; i++) {
            players.push(parsedBody["teams"]["faction1"]["roster_v1"][i]["nickname"]);
        }
    }
});
var options2 = {
    // I get "https://open.faceit.com/data/v4/players?nickname=undefined" instead of 
    // "https://open.faceit.com/data/v4/players?nickname=lonely52"
    url: "https://open.faceit.com/data/v4/players?nickname=" + players[0], 
    headers: headers
};
request(options2, function (error, response, body) {
    if (!error && response.statusCode == 200) {
        var parsedBody = JSON.parse(body);
        console.log(parsedBody["nickname"]); // UNDEFINED
    }
});
app.get("/", function(req, res) {
    res.send(players);  // ["lonely52","Crowned","pstarbang","wolf1E_KZ","Fr0let"]
});
app.listen(3000, function() {
    console.log("Listening on port 3000...");
});
 
     
    