-2

consider i have an array say let arr1=["john","Bruce","Clent"]; and let arr2=[55,33,22];

Then how can i make an object out of this in javascript object should look like:{"john":55,"Bruce":33,"Clent":22}; it should take arr1 as object's keys and arr2 as object'values

NoushadM
  • 111
  • 3
  • 9

1 Answers1

0

You can just loop the array, but use the index to match the key and value.

const arr1=["john","Bruce","Clent"];
const arr2=[55,33,22];

const obj = {};
arr1.forEach((val, i) => {
    obj[val] = arr2[i];
});
Adlan Arif Zakaria
  • 1,706
  • 1
  • 8
  • 13