|
@@ -18,14 +18,14 @@ const fromArray = (array, key, keep = true) => {
|
|
|
throw Error('key must be a string');
|
|
|
}
|
|
|
|
|
|
- return array.reduce((object, item) => {
|
|
|
- const { prop, ...rest } = item;
|
|
|
+ return array.reduce((object, item = {}) => {
|
|
|
+ const { [key]: prop, ...rest } = item;
|
|
|
|
|
|
- if (!prop) {
|
|
|
- return object;
|
|
|
- }
|
|
|
+ if (!prop) { return object; }
|
|
|
+
|
|
|
+ const value = item[key];
|
|
|
+ object[value] = keep ? item : rest;
|
|
|
|
|
|
- object[prop] = keep ? item : rest;
|
|
|
return object;
|
|
|
}, {});
|
|
|
};
|