I have an array with increasing specificity eg.
const locationProperties = ['earth', 'americas', 'canada', 'saskatchewan'];
and I would like an object:
{
earth: {
americas: {
canada: {
saskatchewan: {
// data
}
}
}
}
}
I was thinking to use .reduce to create the object but after applying the transformation in the reducer I am only left with {}
const reducer = (accumulator, item) => {
accumulator[item] = {};
return accumulator[item];
}
const reducedArray = locationProperties.reduce(reducer, {});