Passing global javascript array to another function -
Passing global javascript array to another function -
i have little javascript has globally declared array. values array filled within function foo()
given below:
<html> <head></head> <body> <script> var myarray = []; function foo() { var j = 5; (var = 0; < j; i++) { myarray.push(i+1); } } function bar() { alert(myarray); } </script> </body> </html>
when trying access array in javascript function bar()
, values of array null. how can prepare this?
you have defined function never called it.
try calling foo()
, bar()
this
var myarray = []; function foo() { var j = 5; (var = 0; < j; i++) { myarray.push(i+1); } } function bar() { alert(myarray); } foo(); bar();
jsfiddle
javascript arrays global-variables
Comments
Post a Comment