Deep copying objects in Angular

前端 未结 9 2196
悲&欢浪女
悲&欢浪女 2020-12-01 08:58

AngularJS has angular.copy() to deep copy objects and arrays.

Does Angular also have something like that?

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 09:40

    If the source is an array of objects, using map:

    let cloned = source.map(x => Object.assign({}, x));
    

    OR

    let cloned = source.map((x) => {
                    return { ...x };
                 });
    

提交回复
热议问题