VideosMy ProjectsProgramming BlogGallery
  1. Home
  2. Blog
  3. Convert an array to a object in typescript
Programming Blog

Atom/RSS Feed

typescript

Convert an array to a object in typescript

typescript

To convert an array to a object in typescript you can use the following helper function

Array to Object function

function arrayToObject(array: any[]): Object {
    array.reduce((obj, item) => {
        obj[item.id] = item;
        return obj;
    }, {});
}
Join my mailing list