List.forEach method

Applies to Windows and Windows Phone

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 supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1

Namespace

WinJS.Binding

Library

Base.js

See also

List

 

 

Show:
© 2014 Microsoft