Javascript examples for Array Operation:Array Element
Storing closure functions within array using loop
<html> <head></head> <body> <script> var students = ["a", "b", "c", "d"]; var _class = students.map(function(name, i) { return function() {//from w ww. j av a 2s .co m console.log('Is', name, 'present?', i); }; }); console.log(_class[0]()); console.log(_class[1]()); console.log(_class[2]()); console.log(_class[3]()); </script> </body> </html>