Author Topic: How to clone the datamodel into array without effect of datamodel.  (Read 4464 times)

maDawi

  • Newbie
  • *
  • Posts: 2
    • View Profile
How to clone the datamodel into array without effect of datamodel. when I change the all value of my array into string, the datamodel value change it too into string. how to fix it thank you.

maDawi

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: How to clone the datamodel into array without effect of datamodel.
« Reply #1 on: May 11, 2018, 12:06:57 pm »
this problem was fixed thank this is my solution JSON.parse(JSON.stringify(datamodel.data)).

jlawler.scsi

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: How to clone the datamodel into array without effect of datamodel.
« Reply #2 on: July 26, 2018, 10:41:17 pm »
Another solution is to use Object.assign:

Code: [Select]
var new_data = Object.assign({}, datamodel.data);