I have built a range of image Web addresses on the Wordpress template page such as this:

<?php $attachments = get_posts(array(
        'order'          => 'ASC',
        'post_type'      => 'attachment',
        'post_parent'    => $post->ID,
        'post_mime_type' => 'image',
        'post_status'    => null,
        'numberposts'    => -1,
    ));
    if ($attachments) {
        //set up array of urls
        $image_urls = array();
        foreach($attachments as $attachment){
            $image_object = wp_get_attachment_image_src($attachment->ID,'full');
            $image_urls[] = $image_object[0];
        }
    } ?>

Then, in footer.php, Let me print the array for Javascript such as this:

<script>
var images = [<?php $num_urls = count($image_urls);
                    $num = 1;
                    foreach($image_urls as $image_url) {
                        echo $image_url;
                        $num++;
                        if($num<$num_urls) echo ', ';
                    } ?>];
</script>

I incorrectly assumed that, in concatenating web site page and footer.php, PHP would see the script as continuous, and don't forget the variable value, but that is not the situation, because it returns:

Warning: Invalid argument provided for foreach()

How do you report that $image_urls array to ensure that I'm able to make reference to it later, with no scoping/namespacing danger?

PS It is possible to better method to give a comma in the end however the last item within the latter bit of code?

To securely pass the $image_web addresses around in multiple scripts, declare it such as this:

$GLOBALS['image_urls'] = array();
foreach($attachments as $attachment){
    $image_object = wp_get_attachment_image_src($attachment->ID,'full');
    $GLOBALS['image_urls'][] = $image_object[0];
}

And then, to reference it:

<script>
var images = [<?php $num_urls = count($GLOBALS['image_urls']);
                $num = 1;
                foreach($GLOBALS['image_urls'] as $image_url) {
                    echo $image_url;
                    $num++;
                    if($num<$num_urls) echo ', ';
                } ?>];
</script>

To make certain you don't conflict with anything, you can include a prefix to image_web addresses to point that it's yours.

Script looks fine.

Though, this is better:

<script>
var images = [<?php echo implode(',',$image_urls) ?>];
</script>

I incorrectly assumed that, in concatenating web site page and footer.php, PHP would see the script as continuous, and don't forget the variable value

It will, unless of course Wordpress is odd by doing this, or unless of course the variable is in the function scope (either in file). If that's the case, add this declaration:

global $image_urls;

towards the top of the function(s). Alternatively, reference $image_web addresses everywhere via $GLOBALS. E.g.,

$GLOBALS['image_urls'][] = $image_object[0];

It is possible to better method to give a comma in the end however the last item within the latter bit of code?

Make use of the implode function:

echo implode(', ', $image_urls);

I want quotes around the items too, so:

if (count($image_urls)) {
    echo '"' . implode('", "' $image_urls) . '"';
}

Or, generally, I'd make a move such as this for your kind of loop:

$first = true;
foreach (...) {
    if ($first) $first = false; else echo ', ';
    echo $item;
}