Add value to array in database

Your table does not have a timeofvisit column. The second value of $wpdb->insert expects column value pairs, see here. Try

$wpdb->insert( 
    $table_name, 
    array( 
        'timestamparray' => $timeofvisit,
        'userid' => '2'
    ) 
);