Get a brand list of products for Javascript filter
Presumably you already have the code to retrieve the products you're after.

So just loop through your products and merge your brands in to an array.  

If the brands are just strings, just make an array of the strings, otherwise if they are relations, grab the ids.

Something along these (untested) lines:

{% set brandStrings = [] %}
{% set brandIDs = [] %}

{% for product in products %}
    {# Either of these... #}
    {% set brandStrings = brandStrings|merge([product.brand]) %}
    {% set brandIDs = brandIDs|merge([product.brand.first().id]) %}
{% endfor %}

{# If strings, you've now got an array #}
{# If Ids, and you need to get the names, you can do something like... #}

{% set brands = craft.entries.id(brandIDs).find() %}

{% for brand in brands %}
    {% set brandStrings = brandStrings|merge([brand.title]) %}
{% endfor %}