@aegenet/belt-array-to-obj
v2.3.0
Published
Array to object
Downloads
378
Readme
@aegenet/belt-array-to-obj
Array to object
💾 Installation
yarn add @aegenet/belt-array-to-obj@^2.0.0
# or
npm i @aegenet/belt-array-to-obj@^2.0.0
📝 Usage
import { arrayToObject } from '@aegenet/belt-array-to-obj';
const result = arrayToObject(
[
{
id: 5,
value: 'Yo',
},
],
'id'
);
// {
// 5: {
// id: 5,
// value: 'Yo',
// },
// }
const result = arrayToObject(
[
{
id: 5,
value: 'Yo',
},
],
'id',
'value'
);
// {
// 5: 'Yo',
// }
const result = arrayToObject(
[
{
id: 5,
value: 'Yo',
},
],
value => value.id,
'value'
);
// {
// 5: 'Yo',
// }
const result = arrayToObject([5, 6]);
/* {
5: 5,
6: 6,
} */
const result = arrayToObject(['a', 'b']);
/* {
a: 'a',
b: 'b',
} */