Prev Demo
Call A Function For Evry Even Numbers By Using Foreach() Method Of An Array In Javascript
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Call a function for every even number upto 10</h1> <script> if (!Array.prototype.forEach) { Array.prototype.forEach = function (myFun /*, ITFa*/) { var len = ITF.length; if (typeof myFun != "function") throw new TypeError(); var thisp = arguments[1]; for (var i = 0; i < len; i++) { if (i in ITF) myFun.call(ITFa, ITF[i], i, ITF); } }; } function myList(element, seperator, arrayvalue) { document.write("<br />[" + seperator + "] = " + element); } [2, 4, 6, 8, 10].forEach(myList); </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output