Javascript Data Type How to - Iterate over an array of functions








Question

We would like to know how to iterate over an array of functions.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
function f(){<!--from ww  w  . j a va  2 s  . com-->
}
var arrOfFuncs = [f, f, f, f];
for (var i in arrOfFuncs){
    document.writeln(typeof arrOfFuncs[i]);
    document.writeln(i);
    document.writeln('<br/>');
}
</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: