FrontendDeveloper.in

JavaScript question detail

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

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

var fruits = ["banana", "apple", "orange", "watermelon"];
var fruitsObject = { ...fruits };
console.log(fruitsObject); // {0: "banana", 1: "apple", 2: "orange", 3: "watermelon"}
Back to all JavaScript questions
Get LinkedIn Premium at Rs 399