map Summary Returns a new array with the specified operation applied to all elements of the original array. Signatures Click on a signature to select it and view its documentation. public ResT[] map(ResT(T currentValue) callback) public ResT[] map(ResT(T currentValue, int index) callback) public ResT[] map(ResT(T currentValue, int index, T[] array) callback) Usage public ResT[] map(ResT(T currentValue) callback) public ResT[] map(ResT(T currentValue, int index) callback) public ResT[] map(ResT(T currentValue, int index, T[] array) callback) Returns A new array with the specified operation applied to all elements of the original array. A new array with the specified operation applied to all elements of the original array. A new array with the specified operation applied to all elements of the original array. 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 Returns a new array with the specified operation applied to all elements of the original array. 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. Returns a new array with the specified operation applied to all elements of the original array. 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. Returns a new array with the specified operation applied to all elements of the original array. 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 1234567import System; int[] numbers = [ 2, 4, 6, 8, 10 ];int[] subtract1 = numbers.map(int(int currentValue) { return currentValue - 1;});Console.log(subtract1.toString()); Basic Usage 1234567import System; int[] numbers = [ 2, 4, 6, 8, 10 ];int[] subtract1 = numbers.map(int(int currentValue) { return currentValue - 1;});Console.log(subtract1.toString()); Logging the current array index on each iteration 12345678import System; int[] numbers = [ 2, 4, 6, 8, 10 ];int[] subtract1 = numbers.map(int(int currentValue, int index) { Console.log("index: " + index.toString()); return currentValue - 1;});Console.log(subtract1.toString()); Basic Usage 1234567import System; int[] numbers = [ 2, 4, 6, 8, 10 ];int[] subtract1 = numbers.map(int(int currentValue) { return currentValue - 1;});Console.log(subtract1.toString()); Access original array inside callback 123456789import System;import System.Assert; int[] numbers = [ 2, 4, 6, 8, 10 ];int[] subtract1 = numbers.map(int(int currentValue, int index, int[] array) { assert(currentValue == array[index]); return array[index] - 1;});Console.log(subtract1.toString()); Share HTML | BBCode | Direct Link