[["泼猴","30岁"],["小兰","31岁"]]怎么把数据处理成下面这样[{"name":"泼猴","age":"30岁"},{"name":"小兰","age":"31岁"}]
1 回答
慕盖茨4494581
TA贡献1850条经验 获得超11个赞
var arr = [["泼猴","30岁"],["小兰","31岁"]];
var data = arr.map( function( item ) {
return {
name: item[ 0 ],
age: item[ 1 ]
}
} )
如果用es6,一行就能搞定
let data = arr.map( item =>( { name: item[ 0 ], age: item[ 1 ] } ) )
添加回答
举报
0/150
提交
取消