-5

I have this

array = ["column1", "column2", "column3"]

and this other

array = ["infor1", "infor2", infor3"]

I would like to do this:

{
  column1: infor1,
  column2: infor2,
  column3: infor3
}
Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130

2 Answers2

2

You can try to do something like this,

const props = ["column1", "column2", "column3"];
const values = ["infor1", "infor2", "infor3"];

props.reduce((acc, itm, i) => (acc[itm] = values[i], acc) , {});

You can read more about .reduce here.

Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130
0

var array1 = ["column1", "column2", "column3"]

var array2 = ["infor1", "infor2", "infor3"]

var obj = {};
array1.forEach(function(y, z) {
  obj[y] = array2[z];

});
console.log(obj)
Aishwarya
  • 637
  • 9
  • 21