Get today and yesterday's data from json object where array/object keys are dates
<p>I am using ajax to get a list of sales per day, below is a sample of the ajax being returned to me (I have total control over the front and backend so let me know if the array structure could be better improved to suit the task);</p>

<pre><code>{

"map": [ … ],
"salesCount": {
    "ins_1": {
        "17/09/2012": 5,
        "16/09/2012": 32,
        "15/09/2012": 75,
        "14/09/2012": 78,
        "13/09/2012": 79,
        "12/09/2012": 83,
        "11/09/2012": 74,
 ...
    "ins_2": {
        etc
</code></pre>

<p>I want to get todays sales (17/09/2012) as well as yesterdays. So far I have this:</p>

<pre><code>$.ajax({
    url:        appPath+'application/sale/json',
    type:       'POST',
    dataType:   'json',
    success:    function(response) 
    {
        var keys = null;

        // Get and organise our sales data
        jQuery.each(response.salesCount, function(insurer, dayList) 
        {
            controller.salesData[insurer] = {"days": dayList};

            keys = Object.keys(controller.salesData[insurer].days);
            controller.salesData[insurer].today = controller.salesData[insurer].days[keys[0]];

            // Update sales totals
            $('#'+insurer+' p.today').html(controller.salesData[insurer].today);
</code></pre>

<p>This works OK, but as you can imagine it's not very flexible (and I'm guessing a bad idea trying to rely on a objects non existant order).</p>

<p>I am therefore trying to reference the sales array based on the date. I have tried:</p>

<pre><code>// Work out todays date and sales
var today = new Date();
var todayString = today.getDate()+'/'+today.getMonth()+'/'+today.getFullYear();

console.log(todayString)
console.log(controller.salesData[insurer].days[todayString]);

// outputs: 17/8/2012 and "85"(which is wrong, no idea where it gets that value)
</code></pre>

<p>I've tried changing the array keys to remove the forward slashes etc, but no joy. Surely there is a better way of doing this?</p>

<p>Thank you.</p>
