map和forEach都用于遍历数组,forEach没有返回值。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}
]