const arr = ['xm', 'xh', 'xh']
const res = arr.map((item, index) => {
return item + index
})
console.log(res) // ['xm0', 'xh1', 'xh2']
const arr1 = [{ lab: 'xm', val: '01' },{ lab: 'xh', val: '02' }]
const res1 = arr1.map(item => ({
label: item.lab,
value: item.val
}))
console.log(res1) // [{ label: 'xm', value: '01' },{ label: 'xh', value: '02' }]
ES6 之 map 的用法
最新推荐文章于 2024-04-02 13:49:12 发布