https://github.com/youngwind/array-to-hash-object
将数组转换成对象(可自定义hash key)
https://github.com/youngwind/array-to-hash-object
Last synced: 25 days ago
JSON representation
将数组转换成对象(可自定义hash key)
- Host: GitHub
- URL: https://github.com/youngwind/array-to-hash-object
- Owner: youngwind
- Created: 2016-04-08T07:52:15.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-19T00:52:59.000Z (over 10 years ago)
- Last Synced: 2025-10-20T06:34:19.892Z (10 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# What this package do?
Transform array to object with a custom hash key.
For example.
```
var before = [
{
id:1,
name:"youngwind',
age:24
},
{
id:2,
name:"xiaoye",
age:30
}
];
```
```
// after
{
1:{
name:"youngwind",
age:24
},
2:{
name:"xiaoye",
age:30
}
}
```
# Install
```
npm install array-to-hash-object --save
```
# Usage
```
var arrayToHash = require('array-to-hash-object');
var after = arrayToHash(before,'id');
console.log(after);
```