根据ES6属性编写函数代码
changeCorptype(corptype) { var res = new Map(); this.scompanycodes = this.getAll.filter( (x) => x.CORPTYPE == corptype && !res.has(x.SCOMPANYNAME) && res.set(x.SCOMPANYNAME, 1) ); },
新建一个Map,然后用数组过滤器filter,我上面x.CORPTYPE == corptype这个条件是根据对象的CORPTYPE 的属性进行过滤,
!res.has(x.SCOMPANYNAME)判断Map里面是否包含x.SCOMPANYNAME,不包含的时候添加进Map里面:res.set(x.SCOMPANYNAME, 1),以x.SCOMPANYNAME为Map的key,
res.set(x.SCOMPANYNAME, 1)会返回本身
var res = new Map(); var aa = res.set(1, 1); console.log("---aa=", aa);
去重参考链接: https://blog.csdn.net/ch5256865/article/details/90705660
Map参考链接: https://blog.csdn.net/z93701081/article/details/82939906