MeshWorld India LogoMeshWorld.
TutorialJavaScript1 min read

Convert array to an object in JavaScript

Vishnu
By Vishnu
Convert array to an object in JavaScript

During development we often came across a need of conversion an array to an object.

In this article, lets see how to convert, JavaScript array to an object quickly using widely popular and accepted spread operator (...).

Example

var fruits = ["apple", "grapes", "mangoe", "orange"];
var fruitsObject = { ...fruits };
console.table(fruitsObject);

Output for console.table

(index)Value
0”apple”
1”grapes”
2”mango”
3”orange”

Hope you like this!

Keep helping and happy 😄 coding

With ❤️ from 🇮🇳

Share_This Twitter / X
Vishnu
Written By

Vishnu

Founder & Principal Architect at MeshWorld. Senior engineer and instructor specializing in AI agent systems, scalable web architecture, and modern development workflows.

Enjoyed this article?

Support MeshWorld and help us create more technical content