You can convert an array to an object with the same data using spread(…) operator.
1 2 3 4 5 |
var fruits = ["banana", "apple", "orange", "watermelon"]; var fruitsObject = {...fruits}; // {0: "banana", 1: "apple", 2: "orange", 3: "watermelon"} console.log(fruitsObject); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.