arrayOfObjectToObject

Converts an array of object to a single object

This uses the specified property to convert an array of objects to an object of objects.

import { arrayOfObjectToObject } from "1loc";

const arr = [
    { id: '1', name: 'Alpha', gender: 'Male' },
    { id: '2', name: 'Bravo', gender: 'Male' },
    { id: '3', name: 'Charlie', gender: 'Female' },
]
arrayOfObjectToObject(arr, 'id')

/* 
{
    '1': { id: '1', name: 'Alpha', gender: 'Male' },
    '2': { id: '2', name: 'Bravo', gender: 'Male' },
    '3': { id: '3', name: 'Charlie', gender: 'Female' },
}
*/

Last updated