arrow_back Back to Notebook
typescript
typescript
January 10, 2019

Convert an array to a object in 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;
	}, {});
}

Thanks for reading!

John Wiseman

Full-Stack Software Engineer building scalable digital solutions. specializing in modern web technologies and mission-critical systems.

© 2026

Navigation

Start a Conversation

Ready to discuss your next project? Let's build something extraordinary together.

Get in Touch