【发布时间】:2018-11-28 18:36:01
【问题描述】:
我正在尝试获取一个数组并从中创建一个嵌套对象,其中数组中的每个项目都是前一个项目的属性。
我认为reduce 是做到这一点的方法,但我发现reduce 很难掌握,而且我尝试的每件事都卡在知道如何进入下一个级别。
JS: Reduce array to nested objects 是一个类似的问题,但我尝试了很多变体后仍然无法解决。
const myArray = ['one', 'two', 'three'];
// Intended Output (note, the staticCount is always 1)
{
one: {
staticCount: 1,
two: {
staticCount: 1,
three: {
staticCount: 1
}
}
}
}
【问题讨论】:
标签: javascript