forEach Summary Executes the specified function on each array element. Signatures Click on a signature to select it and view its documentation. public void forEach(void(T currentValue) callback) public void forEach(void(T currentValue, int index) callback) public void forEach(void(T currentValue, int index, T[] array) callback) Usage public void forEach(void(T currentValue) callback) public void forEach(void(T currentValue, int index) callback) public void forEach(void(T currentValue, int index, T[] array) callback) Parameters callback A function which provides the operation logic. Parameters callback A function which provides the operation logic. Parameters callback A function which provides the operation logic. Description Executes the specified function on each array element. This method was standardized in ECMAScript 5 for JavaScript. For web browsers that do not support ECMAScript 5, JS++ will provide a polyfill for this method only if it is used. Executes the specified function on each array element. This method was standardized in ECMAScript 5 for JavaScript. For web browsers that do not support ECMAScript 5, JS++ will provide a polyfill for this method only if it is used. Executes the specified function on each array element. This method was standardized in ECMAScript 5 for JavaScript. For web browsers that do not support ECMAScript 5, JS++ will provide a polyfill for this method only if it is used. Examples Basic Usage 123456import System; int[] numbers = [ 2, 4, 6, 8, 10 ];numbers.forEach(void(int currentValue) { Console.log(currentValue + 1);}); Basic Usage 123456import System; int[] numbers = [ 2, 4, 6, 8, 10 ];numbers.forEach(void(int currentValue) { Console.log(currentValue + 1);}); Using the current array index on each iteration 1234567import System; int[] numbers = [ 2, 4, 6, 8, 10 ];numbers.forEach(void(int currentValue, int index) { Console.log("index: " + index.toString()); Console.log("value + 1: " + (currentValue + 1).toString());}); Basic Usage 123456import System; int[] numbers = [ 2, 4, 6, 8, 10 ];numbers.forEach(void(int currentValue) { Console.log(currentValue + 1);}); Access original array inside callback 12345678import System;import System.Assert; int[] numbers = [ 2, 4, 6, 8, 10 ];numbers.forEach(void(int currentValue, int index, int[] array) { assert(currentValue == array[index]); Console.log(currentValue + 1);}); Share HTML | BBCode | Direct Link