Search
 
SCRIPT & CODE EXAMPLE
 

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: ''}
Comment

PREVIOUS NEXT
Code Example
Javascript :: what is asynchronous 
Javascript :: manage nodejs versions on windows 
Javascript :: isotope js 
Javascript :: video conferencing app with html and js 
Javascript :: remove 0 after decimal point in javascript 
Javascript :: node.js 8 has been deprecated. firebase functions 
Javascript :: javascript Create Strings 
Javascript :: nuxt 3 font awesome 
Javascript :: jquery works until modal is shown 
Javascript :: combine 2 "arrays with objects" and remove object duplicates javascript 
Javascript :: how to create a class javascript 
Javascript :: run for loop every second js 
Javascript :: react 17 
Javascript :: deleteicon material ui improt 
Javascript :: convert string to array javascript 
Javascript :: Adding A forEach Function To An HTMLCollection JavaScript 
Javascript :: Initialize Axios React Redux CRUD API calls 
Javascript :: javascript on screen width change 
Javascript :: react protected route 
Javascript :: monaco editor events 
Javascript :: javascript object get value by key 
Javascript :: event property value in angular 
Javascript :: javaScript setDate() Method 
Javascript :: Sign in with Apple JS 
Javascript :: prevent form submit html javascript jquery 
Javascript :: pwa in angular 
Javascript :: js check string is date 
Javascript :: js combine two arrays 
Javascript :: node localstorage 
Javascript :: lodash round 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =