Use map to get a field in an array object

foreword

I used reduce to write it once before, but now I forget it, and it is difficult to write it a second time if I am not familiar with reduce.
Recently, I have the same requirement. When using the table of ant-design-vue, the table data obtained is very huge. I only need a few of the dozens of fields, so I stepped into the same river again!

use

For data of an array object type:

const dataList = [
  {
    
    
  name:'张晓宇',
    age:'6',
    tel:'13322221111',
  },
   {
    
    
  name:'王大壮',
    age:'5',
    tel:'2331112414',
  },
   {
    
    
  name:'田美丽',
    age:'1',
    tel:'131313',
  },
   {
    
    
  name:'徐向前',
    age:'3',
    tel:'2312323123',
  },
]

Use map to batch process the objects in the array and return a new array.

 const resultList = dataList.map(item => {
    
    
	 return {
    
    
	  	nickName: item.name,
	    age:item.age + '岁',
	  }
 })
console.log(resultList)

before processing
insert image description here

after treatment
insert image description here

that's all!

Guess you like

Origin blog.csdn.net/weixin_54858833/article/details/120728084