I would like to create a JS object made of specific array values. For example, I have an array ["bananas", 5]
and I would like to convert it into an object {"bananas" : 5}
. Could you please let me know how could I do that?
Asked
Active
Viewed 74 times
1

Konstantink1
- 575
- 1
- 8
- 26
1 Answers
2
Object.fromEntries can be used to create an object from an array of arrays:
let input = ["bananas", 5];
let output = Object.fromEntries([input]);
console.log(output);
Where each two-elements array represents a key-value pair from your new object.

mickl
- 48,568
- 9
- 60
- 89