javascript - How to create new json object from exiting one? -
this question has answer here:
i want create new json object exiting one, because if create
var person1= { first name: 'john', last name: 'smith', age: 54, dateofbirth: '31-08-68', } var person2=person1; delete person2.age
this delete age person1, don't want delete age person1, person2. because need initialize other person also. how create new json object exiting object .
you must clone object. quick way is
var person2=json.parse(json.stringify(person1));
Comments
Post a Comment