js 高级函数

1.map()函数

2.reduce函数

3.filter函数

4.sort函数

例子:

function pow(x) {
    return x * x;

}

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];var results = arr.map(pow); // [1, 4, 9, 16, 25, 36, 49, 64, 81]console.log(results);

注意:map()传入的参数是pow,即函数本身。

sort函数对字符串排序按照ASCll排序,不是字符串会默认转化为字符串排序。



原文地址:https://www.cnblogs.com/timeboy/p/9464420.html