1 Replies - 319 Views - Last Post: 26 October 2017 - 10:30 AM

#1 ggwp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-October 17

concat two arrays from two different functions

Posted 26 October 2017 - 08:19 AM

Hi, i'm trying to concat 2 arrays into 1 by Id. Problem is that both arrays are in different functions and i don't know how to access arrays outside their functions.

 
var options = {sportId: 29};
pinnacle.getFixtures(options, function(err, response, body) {
  if (err) throw new Error(err);
  var pinnFixtures = [];
  body.league.forEach(function(leagues){
    leagues.events.forEach(function(event){ 
      pinnFixtures.push({
        'id': event.id,
        'homeTeamName': event.home,
        'awayTeamName': event.away
        });    
    });
  });
});

var options = {sportId: 29, oddsFormat: "DECIMAL"};
pinnacle.getOdds(options, function(err, response, body) {
  if (err) throw new Error(err);
  var pinnOdds = [];
  body.leagues.forEach(function(league){
    league.events.forEach(function(event){
      event.periods.forEach(function(period){
        if (period.moneyline !== undefined) {
          pinnOdds.push({
            'id': event.id,
            'homeTeamOdds': period.moneyline.home,
            'drawOdds': period.moneyline.draw,
            'awayTeamOdds': period.moneyline.away
            }); 
        }
      });
    });
  });
});



Could you please tell me how to do it?
Thank you for your time :)

Is This A Good Question/Topic? 0
  • +

Replies To: concat two arrays from two different functions

#2 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1829
  • View blog
  • Posts: 5,758
  • Joined: 15-January 14

Re: concat two arrays from two different functions

Posted 26 October 2017 - 10:30 AM

You need to store the data somewhere it is accessible. That's probably a decent use case for sessionStorage or localStorage.

https://developer.mo...ge/LocalStorage
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1