See the question and my original answer on StackOverflow

Something like this should do it:

HRESULT DoSomethingWithAJavaScriptArray(VARIANT v)
{
    if (V_VT(&v) != VT_DISPATCH)
        return E_UNEXPECTED;

    _variant_t out; // need comutil.h

   // get the enumeration method see [Reserved DISPIDs][1]
    HRESULT hr = V_DISPATCH(&v)->Invoke(DISPID_NEWENUM, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, NULL, &out, NULL, NULL);
    if (FAILED(hr))
        return hr;

    if (V_VT(&out) != VT_UNKNOWN)
        return E_UNEXPECTED;

    // get the IEnumVariant from the interface
    CComPtr<IEnumVARIANT> pEnum;
    hr = V_UNKNOWN(&out)->QueryInterface(IID_IEnumVARIANT, (void**)&pEnum);
    if (FAILED(hr))
        return hr;

    // do a foreach
    ULONG fetched = 0;
    do 
    {
        _variant_t element;
        hr = pEnum->Next(1, &element, &fetched);
        if ((FAILED(hr)) || (fetched == 0))
            return S_OK;

        // do something with the VARIANT here
            ...
    }
    while(TRUE);
}