I have a scenario where I need to convert an array into an object like this:
let arr = ['ABC', 'DEF']
The desired transformation is:
let obj = {"ABC": 0, "DEF": 0}
Can someone guide me on how to achieve this using ES6 syntax?
let arr = ['ABC', 'DEF']
arr.reduce(x => ({[x] : 0 }))
I tried the above code snippet, but it only gives me {"ABC": 0}
In essence, I want to set all values in the array to a default value of 0. The array could be of any length.
Any help would be appreciated! Thank you!