Array.reduce使用场景
- a.b.c转成{a:{b:{c:1}}}
// strFormatJson('a.b', 1) return {a:{b:1}}
const strFormatJson = (str: string, val:string|number):any => {
return str.split('.').reverse().reduce((t:string|number, o:string) => ({[o] :t} as any), val);
};
应用reduce操作方式!!!