Share via


List.forEach method

Calls the specified callback function for each element in a list.

Syntax

list.forEach(callback, thisArg);

Parameters

  • callback
    Type: Function

    A function that accepts up to three arguments. The function is called for each element in the list. The arguments are as follows:

    • value: the value of the element.

    • index: the current index.

    • array: the array that contains the element.

  • thisArg
    Type: Object

    An object to which the this keyword can refer in the callback function. If thisArg is omitted, undefined is used.

Return value

This method does not return a value.

Examples

The following code shows how to use the forEach method.

var array = ["ab", "cd", "ef"];

var list = new WinJS.Binding.List(array);
list.forEach(showIteration);

function showIteration(value, index, array) {
    console.log("value: " + value);
    console.log(" at index: " + index);
    console.log(" in " + array);
    console.log("<br />");
}

Requirements

Minimum WinJS version

WinJS 1.0

Namespace

WinJS.Binding

See also

List