add objectize_array
method to convert an array of objects to a dictionary of objects by specified key
This commit is contained in:
parent
f84a4bb406
commit
6c9245ba0c
@ -10,6 +10,10 @@ module.exports = {
|
|||||||
|
|
||||||
sleep: (ms) => new Promise((resolve, reject) => setTimeout(resolve, ms)),
|
sleep: (ms) => new Promise((resolve, reject) => setTimeout(resolve, ms)),
|
||||||
|
|
||||||
|
objectize_array (arr, key) {
|
||||||
|
return arr.reduce((obj, item) => ({ ...obj, [item[key]]: item }), {})
|
||||||
|
},
|
||||||
|
|
||||||
deepFreeze (obj) {
|
deepFreeze (obj) {
|
||||||
if (typeof obj !== 'object' || obj === null) {
|
if (typeof obj !== 'object' || obj === null) {
|
||||||
return obj
|
return obj
|
||||||
|
Loading…
Reference in New Issue
Block a user