I have an array like this:
const companyNames = ["A", "B", "C"];
I want to convert it to a something like this:
const companyNames = {
0: 'A',
1: 'B',
2: 'C'
};
I have an array like this:
const companyNames = ["A", "B", "C"];
I want to convert it to a something like this:
const companyNames = {
0: 'A',
1: 'B',
2: 'C'
};
You can use Spread Operator
:
{ ...["A", "B", "C"] }
You can use forEach
:
var companyNames = ["A", "B", "C"];
var data = {};
companyNames.forEach(function(value, index) {
data[index] = value;
})
console.log(data)