I have a small javascript which has a globally declared array. The values for that array are filled inside the function foo() as given below:
<html>
<head></head>
<body>
<script>
var myArray = [];
function foo() {
var j = 5;
for (var i = 0; i < j; i++) {
myArray.push(i+1);
}
}
function bar() {
alert(myArray);
}
</script>
</body>
</html>
When I trying to access that array in another javascript function bar(), the values of array are null. How can I fix this?