I would take up 2 javscript files.
In one file i declare an array of 5 elements.
Can anyone tell me how can i retrieve those array elements in another file.
I would take up 2 javscript files.
In one file i declare an array of 5 elements.
Can anyone tell me how can i retrieve those array elements in another file.
Suppose one js file name script1.js
and another script2.js
script1.js
var ar=["1","2"];
script2.js
console.log(ar);
in your html file place your first script file before 2nd script file
<script src="script1.js"></script>
<script src="script2.js"></script>
sample.js
var a = new a();
function a()
{
this.array = [1,2,3];
}
sample2.js
function b()
{
alert(a.array);
}
sample1.html
<!DOCTYPE html>
<html>
<head>
<script src = "sample.js"></script>
<script src = "sample2.js"></script>
<script type="text/javascript"> b();</script>
</head>
<body>
</body>
</html>