- All qualified only through:
var numbers = [1,2,3,4,5,4,3,2,1]; var everyresult = Numbers.every (function(item, index, array) { return (item > 2); }); alert (everyresult); // false
Each item in the previous example is greater than 2 to return true.
- any one pass through:
var numbers = [1,2,3,4,5,4,3,2,1 var Someresult = numbers.some (function (item, index, array) { return ( Item > 2); }); alert (Someresult); // true
In the previous example, There is a value greater than 2 to return true.
- Filter Some dross:
var numbers = [1,2,3,4,5,4,3,2,1 var Filterresult = numbers.filter ( function return< /span> (item > 2); }); alert (Filterresult); // [3,4,5,4,3]
In the previous example, Filter out more than 2.
- One-to-one mapping:
var numbers = [1,2,3,4,5,4,3,2,1]; var mapresult = Numbers.map (function(item, index, array) { return item * 2; }); alert (mapresult); // [2,4,6,8,10,8,6,4,2]
In the example above, multiply each item by 2.
- Iteration: Using For-each.
- reduction: Reduce.
var values = [1,2,3,4,5 var sum = values.reduce (function (prev, cur, index, array) { return Pre V + cur; }); alert (sum); // 15
The Summation sum is returned, and 5 items are reduced to 1 items.