Skip to main content
InterviewHubPRO
Section Overview
Q373

Question 373 of 536

Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)

70%
JavaScript & V8 Internals (536 Qs)•Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)

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

senior LevelCode ExampleAsync & PromisesEvent LoopData Structures

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

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