2

Following code snippet:

toBarChart =  function (d){
  var tData = [{values: []}];
    angular.copy(d, tData[0].values)
  return tData;
}
norbitrial
  • 14,716
  • 7
  • 32
  • 59
  • 3
    Possible duplicate of [What is the most efficient way to deep clone an object in JavaScript?](https://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-deep-clone-an-object-in-javascript) – Alexander Staroselsky Mar 21 '19 at 14:22
  • 1
    var deepClone = JSON.parse(JSON.stringify(obj)); This is one of the simplest way in native JS to deep clone an object. – Priyesh Diukar Mar 21 '19 at 14:26

3 Answers3

3

Just simply use the Object.assign(...) which will copy all the values of properties from the source to target object.

Let's see an example:

(function() {
  let originalData = {
    title: 'example value'
  };

  let targetData = {};

  Object.assign(targetData, originalData);

  targetData.title = 'updated value';

  console.log('source and target', {
    original: originalData.title,
    target: targetData.title
  });
})();

In your case I assume you can do the following:

toBarChart =  function (d){
  var tData = [{values: []}];
    Object.assign(d, tData[0].values)
  return tData;
}
norbitrial
  • 14,716
  • 7
  • 32
  • 59
1

lodash is good for deep copying in Angular

import * as _ from 'lodash';

let newCopy = _.cloneDeep(objectToBeCopied);
Dilshan Liyanage
  • 4,440
  • 2
  • 31
  • 33
0

You can Try cloneDeep function from lodash.

MD. Khairul Basar
  • 4,976
  • 14
  • 41
  • 59