Javascript examples for Array Operation:Array Element
Return function from a function and save it to an array
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <script type="text/javascript"> var a = []; for (i = 0; i < 10; i++) { a[i] = alertFunc(i); } function alertFunc(i){ return function() {// ww w.jav a 2 s .c om console.log(i); }; }; a[5](); </script> </body> </html>