@冴宇 and @cool_zjy’s solutions are similar, but they both generate a new object. According to the original question, the initial value of reduce is passed into Obj instead of {}. The former does not require ES6 features, the latter does.
@hsfzxjy’s method seems to be simple, but it will generate a lot of intermediate objects, so the efficiency should not be very good.
Object.assign should be the simplest solution. Of course, maybe a simpler API can be found in the Lodash library to implement it.
@冴宇 and @cool_zjy’s solutions are similar, but they both generate a new object. According to the original question, the initial value of
reduce
is passed intoObj
instead of{}
. The former does not require ES6 features, the latter does.@hsfzxjy’s method seems to be simple, but it will generate a lot of intermediate objects, so the efficiency should not be very good.
Object.assign
should be the simplest solution. Of course, maybe a simpler API can be found in the Lodash library to implement it.Laxative. Using the ES6 Spread Operator can be more concise, but the essence is the same
Question and answer first, use Object.assign() to merge, I don’t know if there are other good methods