1

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?

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.