How to add a date to an item thats is scraped with cheerio

I have created a small script that will scrape data of football matches. From the website I will scrape the matchdate, time, home team and away team.

The script I have created:

var cheerio = require('cheerio');
var request = require('request');

request('https://www.fotmob.com/leagues/47/matches/', function (error, response, html) {
  if (!error && response.statusCode == 200) {
    var $ = cheerio.load(html);

    $('.fm-fixture').each(function(i, element){

      var a = $(this);
      var homeTeam = a.children().eq(1).children().text();
      var awayTeam = a.children().eq(3).children().text();
      var time = a.children().eq(2).children().text();
      var day = a.prev().text();

      var metadata = {
        homeTeam: homeTeam,
        awayTeam: awayTeam,
        time: time,
        day: day
      };
      console.log(metadata);
    });

  }
});

The output now:

{ homeTeam: 'Burnley',
  awayTeam: 'AFC Bournemouth',
  time: ' 16:00',
  day: 'May 13, 2018  ' }
{ homeTeam: 'Crystal Palace',
  awayTeam: 'West Bromwich Albion',
  time: ' 16:00',
  day: '' }
{ homeTeam: 'Huddersfield Town',
  awayTeam: 'Arsenal',
  time: ' 16:00',
  day: '' }

But the problem is that on the website per date all the matches from that day are displayed. So only the first one scraped will get the date from that day. How can I add to the other matches also the date May 13, 2018 for example?

You can loop through the data and add/update date from the first one.

data.foreach(function(item, index){
if(!item.day) data[index].day = data[0].day
})

You do know there are APIs available with this info?

I’m testing the cheerio module and not going to use this data. I want to use an api to get football.
Which apis do you recommend? There are a lot of apis with football data.

I signed up for sport radar. Haven’t tried any others but I know there are others out there.