array2objectarray
v1.0.1
Published
array2ObjectArray
Downloads
4
Readme
// 数组转为对象数组
var array2ObjectArray = require('./lib/array2ObjectArray.js');
var arr = [
{
id: 1,
name: '张三',
age: 20
},{
id: 2,
name: '王二',
age: 16
},{
id: 3,
name: '李四',
age: 24
}
]
var object = array2ObjectArray.arr2ObjArr(arr, 'id')
// output
object {
'1': [ { id: 1, name: '张三', age: 20 } ],
'2': [ { id: 2, name: '王二', age: 16 } ],
'3': [ { id: 3, name: '李四', age: 24 } ]
}