Script dependencies generates different outputs

I think the for each loop is a little wonky, if I’m understanding your question, you can try the following.👌

// Generate a list of dependencies for a given handle.
function get_deps() {
    global $wp_scripts;

    $deps = array();
    foreach ( $wp_scripts->registered as $handle => $script ) {
        if ( in_array( 'jquery', $script->deps, true ) ) {
            $deps[] = $handle;
        }
    }

    echo '<pre>';
    print_r( $deps );
    echo '</pre>';
}

Would output the following;

Array
(
    [0] => common
    [1] => editor
    [2] => wp-ajax-response
    [3] => wp-api-request
    [4] => heartbeat
    [5] => jquery-ui-core
    [6] => jquery-effects-core
    [7] => jquery-form
    [8] => jquery-color
    [9] => schedule
    [10] => etc...

)

Edit: Added for completeness.

// Generate a list of dependencies for a given handle.
function get_deps() {
    global $wp_scripts;

    $deps = array();
    foreach ( $wp_scripts->registered as $handle => $script ) {
        if ( in_array( 'jquery-migrate', $script->deps, true ) ) {
            $deps[] = $handle;
        }
    }
    
    return $deps;
}

function foo_enqueue_scripts() {
    $the_deps = get_deps();
    
    echo '<pre>';
    print_r( $the_deps );
    echo '</pre>';
    
    /* output from print_r:
     * Array
     * (
     *     [0] => jquery
     * )
     */
    
    wp_enqueue_script( 'my-foo-js', get_stylesheet_directory_uri() . '/foo.js', $the_deps, '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'foo_enqueue_scripts' );