DEV Community

Vishnu Damwala
Vishnu Damwala

Posted on • Originally published at meshworld.in

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);
Enter fullscreen mode Exit fullscreen mode

Output for console.table

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

Read others post on our site MeshWorld

Hope you like this!

Keep helping and happy ๐Ÿ˜„ coding

With โค๏ธ from ๐Ÿ‡ฎ๐Ÿ‡ณ

Top comments (0)