let obi=[ { price:123 } , { price:23 } , { price:45 } ]; let res=obi.reduce((obj,cur,index)=>{ obj[`${cur["price"]}-${index+1}`]=obi; // console.log(obj); return obj; },{}); console.log(JSON.stringify(res,null,2)); function upload(params){ let options={ size:9999 } options=Object.assign(options,params);//将2个对象进行合并 console.log(JSON.stringify(options,null,2)); } upload({size:11,tupe:"jpeg"});
Object.assign() 方法用于将所有可枚举属性的值从一个或多个源对象分配到目标对象。它将返回目标对象。
const target = { a: 1, b: 2 };
const source = { b: 4, c: 5 };
const returnedTarget = Object.assign(target, source);
console.log(target);
// expected output: Object { a: 1, b: 4, c: 5 }
console.log(returnedTarget);
// expected output: Object { a: 1, b: 4, c: 5 }