repl.txt (1454B)
1 2 {{alias}}( collection, fcn, predicate[, thisArg] ) 3 While a test condition is true, invokes a function for each element in a 4 collection. 5 6 The condition is evaluated *after* executing the provided function; thus, 7 `fcn` *always* executes at least once. 8 9 When invoked, both the predicate function and the function to apply are 10 provided three arguments: 11 12 - `value`: collection value 13 - `index`: collection index 14 - `collection`: the input collection 15 16 If provided an empty collection, both `value` and `index` are `undefined`. 17 18 Parameters 19 ---------- 20 collection: Array|TypedArray|Object 21 Input collection over which to iterate. If provided an object, the 22 object must be array-like (excluding strings and functions). 23 24 fcn: Function 25 The function to invoke for each element in a collection. 26 27 predicate: Function 28 The predicate function which indicates whether to continue iterating 29 over a collection. 30 31 thisArg: any (optional) 32 Execution context for the applied function. 33 34 Returns 35 ------- 36 out: Array|TypedArray|Object 37 Input collection. 38 39 Examples 40 -------- 41 > function predicate( v ) { return v === v; }; 42 > function logger( v, i ) { console.log( '%s: %d', i, v ); }; 43 > var arr = [ 1, 2, 3, 4, NaN, 5 ]; 44 > {{alias}}( arr, logger, predicate ) 45 0: 1 46 1: 2 47 2: 3 48 3: 4 49 4: NaN 50 51 See Also 52 -------- 53