assign an element value as key in array of objects

Solutions on MaxInterview for assign an element value as key in array of objects by the best coders in the world

showing results for - "assign an element value as key in array of objects"
Amin
13 Jan 2021
1var keys = ['HP', 'QP', 'PS'],
2    object = Object.assign(...keys.map(key => ({ [key]: 0 })));
3    
4console.log(object);