javascript - Get array entries from another js file -


i have following program structure:

index.html:

<html>    <head>       <script src="first.js"></script>       <script src="second.js"></script>   </head> ...</html> 

first.js:

"use strict"; var array = [];  $(document).ready(function () {  $("#xy").on("tap", function () {    array.push(new arrayitem()); } ... 

second.js:

console.log(array); 

in first.js, push objects array, console.log in second.js says, array empty. doing wrong? thanks...

as previous users have stated, console.log being run while array being populated after document has been loaded. however, if have console.log run when document loaded, still won't see variable. want when on 'tap' event, send array function that's defined in second.js so:

in first.js

"use strict"; var array = [];  $(document).ready(function () {  $("#xy").on("tap", function () {    array.push(new arrayitem());    somefunction(array); } 

in second.js

function somefunction(array) {     console.log(array);     // rest of code requires 'array' here } 

this way, every time fire on tap event, somefunction handed array.