Sometimes it is useful to iterate over function arguments programmatically. Function arguments can be access using arguments variable. Here is code snippet for this.
<script type="text/javascript">
function f1() {
document.write("------f1 called typeof(arguments)=" +typeof(arguments) + "<br/>");
for (var i=0; i < arguments.length; i++) {
document.write("arg" + i + "=" + arguments[i] + "<br/>");
}
}
f1("arg1");
f1("arg1", "arg2");
</script>Note that Javascript method forEach cannot be use on arguments.