es6新增方法map()

通常用法为:

  • 用法为:arr.map()
    • 这个方法常常被用来作数据交互映射
    • 返回值为一个新的数组,数组中的元素为原始数组元素通过处理后的值
  • 注意:map()不会对空数组检测
  • map()不会改变原始数据
  • 小例子
<script>
    let arr = [
        {title:'aaa',read:50},
        {title:'bbb',read:50},
        {title:'ccc',read:50}
    ];
    let newArr = arr.map((item, index, arr)=>{
        let json = {}
        json.t = `${item.title}`;
        json.r = item.read+100;
        return json
    });
    console.log(newArr)


</script>
复制代码

输出结果为:

[
    {t:'aaa',r:150},
    {t:'bbb',r:150},
    {t:'ccc',r:150}

]
复制代码

若有错误请指出

相关文章
相关标签/搜索