0
点赞
收藏
分享

微信扫一扫

ES6 之 map 的用法

勇敢乌龟 2022-04-14 阅读 36
javascript
    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 条评论