Set去重

var array = [1,1,1,2,3,4,4,5,6];
var a = new Set(array );
var b = [];
b = [...a]//[1,2,3,4,5,6]  去重效果

Map数据映射 可以重组数据

var a = [{ id: 1, name: 'zhangsan' }, { id: 2, name: 'zhangsi' }, { id: 3, name: 'wangwu' }];
var c = a.map(obj => {
                let oS = {};
                oS['ids'] = obj.id;
                oS['bbName'] = obj.name;
                return oS;
            })// c =  [{ ids: 1, bbName: 'zhangsan' }, { ids: 2, bbName: 'zhangsi' }, { ids: 3, bbName: 'wangwu' }]

filter数据过滤

var a = [{ id: 1, name: 'zhangsan' }, { id: 2, name: 'zhangsi' }, { id: 3, name: 'wangwu' }];
var c = a.filter(obj => {
                if(obj.id === 3)
                    return obj;
            })// c = [ { id: 3, name: 'wangwu' }]
posted on 2018-10-19 14:46  佑之以航  阅读(177)  评论(0编辑  收藏  举报