JS Coding Questions Logo
JS Coding Questions
#369💼 Interview💻 Code

What is the easiest way to convert an array to an object

Advertisement

728x90

You can convert an array to an object with the same data using spread(...) operator.

javascript
1var fruits = ["banana", "apple", "orange", "watermelon"];
2
3var fruitsObject = { ...fruits };
4
5console.log(fruitsObject); // {0: "banana", 1: "apple", 2: "orange", 3: "watermelon"}

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 27

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
369of476
What is the easiest way to convert an array to an object | JSCodingQuestions.com