Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js object from array of keys

const arr = ['name', 'age', 'country'];

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

console.log(obj); // {name: '', age: '', country: ''}
Source by bobbyhadz.com #
 
PREVIOUS NEXT
Tagged: #js #object #array #keys
ADD COMMENT
Topic
Name
3+1 =