Q:

Check an API call for differences

I make an API call and pull down JSON data and store in an Array.
Whats the best way to periodically check if there is a change in the Array that's pulled down and return an Array of the new data?
JSON from API call:
{
  success: true,
  message: "",
  result: [{
      Currency: "GBP",
      IsActive: true,
      BaseAddress: "1N52wHoVR79PMDishab2XmRHsbekCdGquK",
      Notice: null
    },
    {
      Currency: "USD",
      IsActive: true,
      BaseAddress: "LhyLNfBkoKshT7R8Pce6vkB9T2cP2o84hx",
      Notice: null
    },
    {
      Currency: "YEN",
      IsActive: true,
      BaseAddress: "D9GqmkGCpgtnXP7xMD78v9xfqeDkqBZBMT",
      Notice: null
    }
  ]
};

Store in an array:
const currencies = [...new Set(data.result.map(a => a.Currency))];

console.log(currencies);

Now say the website add CHF how would I poll the API and get an Array just containing the new data?
Specifically whats the best way to schedule another API call, using setTimeout or is there a better way?
Also, how do I then compare the first array with the second array and return an array containing the difference?

A:

I guess you are making it little bit complex. Best way to achieve this purpose is web sockets.
Web sockets are used to have communication between client and server.
Lets say if you create a server in nodejs and you have a browser client. Web socket will create a communication between server and client.
If there is any changes made by server in your "ARRAY", server can send a notification that a changes has been made in the array so you can make a new request to get the updated array or server can directly send updated array to client.
Advantage of this approach is that there is not need of pull request. Server will push the data so there will be no period check between server and client. This can save a lot of time plus performance.
Please research about web sockets and implement it.

