Angular 使用新值复制和更新对象并存储到数组

Angular 使用新值复制和更新对象并存储到数组,angular,typescript,angular5,Angular,Typescript,Angular5,我正在尝试克隆和更新一个对象以作为新实例存储在数组中。但这不管用 有人帮我解决这个问题吗 以下是我的尝试: public getAppPropeties(locales):Observable<any>{ const msgParms = []; locales.forEach((locale, i) => { this.messageParam['bd']['locale']=String(locale);

我正在尝试克隆和更新一个对象以作为新实例存储在数组中。但这不管用

有人帮我解决这个问题吗

以下是我的尝试:

 public getAppPropeties(locales):Observable<any>{

        const msgParms = [];

        locales.forEach((locale, i) => {

            this.messageParam['bd']['locale']=String(locale);

            msgParms[i] = Object.assign({}, this.messageParam);    ;

        });

        console.log( 'msgParms', msgParms ); //getting last value

}
公共GetAppProperties(地区):可观察{ 常量msgParms=[]; locales.forEach((locale,i)=>{ this.messageParam['bd']['locale']=String(locale); msgParms[i]=Object.assign({},this.messageParam); }); console.log('msgParms',msgParms);//获取最后一个值 } 我试着这样做:

msgParms[i]=Object.assign({},this.messageParam,{“bd”:{“locale”:locale})


工作正常

您的英语,因此您的问题,非常不清楚。我正在尝试克隆和更新现有对象中的某些值,并将其作为新对象强插入数组中。可能重复使用this.messageParam.bd.locale=String(locale)和msgParam.push(object.assign({},this.messageParam))@Eliseo做的事情和OP的代码完全一样。