PP.map

Syntax

map(input_array: Array, converter_function: function, function_context: Array);

Parameters

input_array. Initial array.

converter_function. Function performed for elements of initial array. it has the following parameters: element - array element, element_index - its index, input_array - initial array.

function_context. Function context.

Description

The map method determines the array, each element of which is a result of executing a specified function for corresponding element in the source array.

Comments

This method returns an Array value.

Example

To execute the example, the HTML page must contain link to the PP.GraphicsBase.js scenario file. Determine an array of integers, next multiply each element in this array by two:

// Determine an integer array
var elements = [5, 9, 6, 7, 2];
console.log("Source array of elements: [" + elements + "]");
// Determine callback function
var callback = function (element) {
    element *= 2;
    return element;
};
var map = PP.map(elements, callback, this);
console.log("New array of elements: [" + map + "]");

After executing the example the browser console displays integer elements of the array increased two times:

Initial array of elements: [5,9,6,7,2]

New array of elements: [10,18,12,14,4]

See also:

PP