数组api 使用记录

数组的api在日常业务中使用频率相当高,所以高效且美观的处理,尤为重要
Reduce
1.

let phoneArray=[{
    
    contactNo:1212123},{
    
    contactNo:23121215}]
          this.phoneArray2 = phoneArray.reduce((acc, cur) => {
    
    
            if (!cur.id) {
    
    
              acc.push(cur.contactNo);
            }
            return acc;
          }, []);
得到['1212123','23121215']
let val=[{
    
    id:'123'},{
    
    id:'456'},{
    
    id:'789'}]
this.selectedIds = val?.reduce((acc, cur, index) => {
    
    
        return (acc += cur.id + ',');
      }, '');
得到 this.selectedIds='123,456,789'

猜你喜欢

转载自blog.csdn.net/weCat_s/article/details/111554917