How to convert an array values to object keys in Node.js

1 Answer

0 votes
const arr = ['nodejs', 'c', 'c++'];

const obj = arr.reduce((accumulator, value) => {
  	return {...accumulator, [value]: ''};
}, {});

console.log(obj);

  
  
  
  
/*
run:
  
{ nodejs: '', c: '', 'c++': '' }
  
*/

 



answered May 23, 2022 by avibootz

Related questions

1 answer 234 views
1 answer 238 views
1 answer 228 views
2 answers 262 views
1 answer 215 views
1 answer 216 views
216 views asked Feb 26, 2022 by avibootz
...