I am trying to get an array of "records" that each contain an array of "field objects" (each with properties .name, .value, and .fid).

Each array of records is obtained via an AJAX call to a database via an API call.

I want to be able to iterate through these later with some other code, but, for the moment, I'm trying to get the resultant array of arrays.

I'll be honest, I'm struggling with how to do this with promises...

If I was doing this synchronously I'd use a FOR TO loop and push each iteration into an array, but async is causing me issues...

My current code is as follows. This returns a single array of fields, rather tham an array of arrays. I think I need to push each 'thisArray' to another array. Anyone willing to help?:

NOTE: 

ridList is a simple array of DB record IDs, e.g.: ["391", "392", "393", "394", "395", "398", "399", "400", "396", "397", "437"]

AVMI\_db is the URL the AJAX call gets its data from.

```
///////////////////////////////////////////////////////////////
// Get record info for each array member
///////////////////////////////////////////////////////////////
function AVMI_getMultipleRecordInfoFromArray(ridList, AVMI_db) {
    var promises = [];

    $.each(ridList, function (index,value) {
        var def = new $.Deferred();
        var thisArray = [];
        $.get(AVMI_db, {   //******* ITERATIVE AJAX CALL ******* 
            act: 'API_GetRecordInfo', 
            rid: value
        }).then(function(xml2) {
            $(xml2).find('field').each(function() {
                var $field = {};
                $field.fid = $(this).find('fid').text();
                $field.name = $(this).find('name').text();
                $field.value = $(this).find('value').text();
                thisArray.push($field);
            });
            def.resolve(thisArray);
        });
        promises.push(def);    
    });    

    return $.when.apply(undefined, promises).promise();
};

```