数组映射 ,重新整理,配合return,返回一个新数组,没有return,相当于forEach()
arr.map(val,index,arr)
let arr = [ {title:'name',age:'10'}, {title:'aaa',age:'10'}, {title:'aaa',age:'10'}, {title:'aaa',age:'10'}, ] let map = arr.map((val,index,arr) => { let json = {} json.t = val.title; json.a = val.age; return json; }) console.log(map);
Run Code:
[ { t: 'name', a: '10' }, { t: 'aaa', a: '10' }, { t: 'aaa', a: '10' }, { t: 'aaa', a: '10' } ]