filter()
    对数组过滤,基于遍历
    filter(function,this指向)
    filter()执行完以后会返回一个新数组

    1. var personArr = [
    2. {name: '12' , src : '../12/123',des:'1221',sex:'m'},
    3. {name: '13' , src : '../13/1234',des:'1222',sex:'f'},
    4. {name: '14' , src : '../14/1234',des:'1223',sex:'m'},
    5. {name: '15' , src : '../15/1245',des:'12214',sex:'f'},
    6. ];
    7. var newPersonArr = personArr.filter(function(ele,index,self){return ele.sex =='f';},personArr)
    8. console.log(newPersonArr)

    filter()原理

    1. var personArr = [
    2. {name: '12' , src : '../12/123',des:'1221',sex:'m'},
    3. {name: '13' , src : '../13/1234',des:'1222',sex:'f'},
    4. {name: '14' , src : '../14/1234',des:'1223',sex:'m'},
    5. {name: '15' , src : '../15/1245',des:'12214',sex:'f'},
    6. ];
    7. Array.prototype.myFilter = function(fun){
    8. arr=[];
    9. var len = this.length;
    10. _this = arguments[1] || window;
    11. for (var i = 0 ; i < len ; i++){
    12. fun.apply(_this,[this[i],i,this]) && arr.push(this[i]); //此处&&的意思是当前面为真时才会执行&&后面的
    13. }
    14. return arr;
    15. }
    16. var newPersonArr = personArr.myFilter(function(ele,index,self){
    17. return ele.sex =='m'
    18. },personArr)

    map()
    映射作用 返回一个新数组,
    filter()是有选择的获取数据而map()是将你要某种属性的数据全部给你 ,比如用filter()选取性别中的男生,而map()会把性别这个属性下所有数据添加进一个新数组返回给你
    map(function,this指向)
    返回值 返回一个新数组

    1. var personArr = [
    2. {name: '12' , src : '../12/123',des:'1221',sex:'m',age: 10},
    3. {name: '13' , src : '../13/1234',des:'1222',sex:'f',age:15},
    4. {name: '14' , src : '../14/1234',des:'1223',sex:'m',age:23},
    5. {name: '15' , src : '../15/1245',des:'12214',sex:'f',age:14},
    6. ];
    7. var arr = personArr.map(function(ele){
    8. ele.age += ele.age;
    9. return ele;
    10. })

    map()原理

    1. var personArr = [
    2. { name: '12', src: '../12/123', des: '1221', sex: 'm', age: 10 },
    3. { name: '13', src: '../13/1234', des: '1222', sex: 'f', age: 15 },
    4. { name: '14', src: '../14/1234', des: '1223', sex: 'm', age: 23 },
    5. { name: '15', src: '../15/1245', des: '12214', sex: 'f', age: 14 },
    6. ];
    7. Array.prototype.myMap = function (fun) {
    8. var arr = [];
    9. var _this = arguments[1] || window;
    10. var len = this.length;
    11. for (var i = 0; i < len; i++) {
    12. arr.push(fun.call(_this, this[i], i, this));
    13. }
    14. return arr;
    15. }
    16. var newPersonArr = personArr.myMap(function (ele, index, self) {
    17. return ele.name;
    18. })
    19. console.log(newPersonArr)

    split() 与 join()
    split()按照指定的格式将string拆分为数组

    1. var lrc = `[00:01.06]难念的经
    2. [00:03.95]演唱:周华健
    3. [00:06.78]
    4. [00:30.96]笑你我枉花光心计
    5. `;
    6. var parts = lrc.split("\n");
    7. // 结果为 parts["[00:01.06]难念的经","[00:03.95]演唱:周华健",“[00:06.78]”,“[00:30.96]笑你我枉花光心计”]

    join()将数组按照自定义的格式转化为string

    1. var arr = [1,2,3,4,5,7];
    2. var a = arr.join('-'); // a = "1-2-3-4-5-7"

    concat()
    拼接两个数组

    1. var arr = [1,2,3,4,5,7]
    2. var arrs = [1,2,3,4,5,6,7]
    3. arr.concat(arrs);