How to create an object from two arrays in Node.js

1 Answer

0 votes
const arr1 = ['q', 'lang', 'limit'];
const arr2 = ['NodeJS', 'en', 10];

const obj = {};

arr1.forEach((element, index) => {
  	obj[element] = arr2[index];
});

console.log(obj);

  


  
/*
run:
  
{ q: 'NodeJS', lang: 'en', limit: 10 }
  
*/

 



answered May 21, 2022 by avibootz

Related questions

1 answer 85 views
1 answer 112 views
1 answer 138 views
1 answer 235 views
1 answer 165 views
3 answers 217 views
...