ES6 之 map 的用法

阅读 36

2022-04-14

    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' }]

精彩评论(0)

0 0 举报