How do I get values of array into global variable?

```
var p = new Array();
var all_Y_values = 0;
for (var r = 0; r < embeddedCells.length; r++)
{
    p[r] = embeddedCells[r].attributes.position.y;
    all_Y_values = p[r], all_Y_values; 
    console.log("all y values: " + all_Y_values); //prints all values
}
console.log("all y values: " + all_Y_values); //prints only last value

```

Right now inside the loop I am able to print all values inside loop but when I print the same outside loop its printing only last value.