I'm refactoring some code that currently has these three variables:
var sites=["London","Dublin","Paris"];
var mostRecent = {London: '',Dublin: '',Paris: ''};
var ackStatus = {London: '',Dublin: '',Paris: ''};
That seems unnecessarily verbose, and makes adding a site difficult, so I combined them into one array of objects here:
var sites = [
{name: 'London', mostRecent:'', ackStatus:''},
{name: 'Dublin', mostRecent:'', ackStatus:''},
{name: 'Paris', mostRecent:'', ackStatus:''}
];
How do I choose an object to update based on the site name? The variables are currently being accessed like this:
ackStatus["London"] = xmlhttp.responseText;
Alternatively, is there a better way to refactor this than what I did? Three arrays is not terrible, but if the code expands much more, it will get confusing.