'Wordpress: Output list with taxonomy term IDs in WP_Query loop

I would like to output in a WP_Query loop a list with the term IDs of a certain taxonomy ('genre') of the respective post. I managed to output the first ID (as you can see in the code example). How can I get a comma separated list of all term IDs of the taxonomy 'genre' for 'terms' in the 'tax_query' array?

function my_function( $query_args) {
    $terms = get_the_terms( $post->ID, 'genre');
    $termlist = $terms[0]->term_id;
    

$query_args = array(
    'post_type' => 'portfolio',
    'orderby' => 'date',
    'order' => 'ASC',
    'tax_query' => array(
        array(
            'taxonomy' => 'genre',
            'field'    => 'term_id',
            'terms'    => array($termlist),
        ),
    ),
);

    return $query_args;

}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source