56
55 How do you mean?
- What does it do?
- Why is it bad?
- Why is it the only good option?
- What are you trying to do?
JSON.stringify() takes an object and turns it into a text representation of said object.
JSON.parse() is the opposite of it (it takes a text representation of an object and turns it into a real object.)
Its bad because it looks like an hack (and lets be honest, it is a hack)
The reason I need it is because I need to clone an object (and all the objects inside of it). I can't just write
Code:
let inputData = this.inputFieldData;
because in JS objects are always passed by reference (thus, if I do that inputData refers to the same memory as this.inputFieldData and as a result any changes I do to inputData will also happen to this.inputFieldData)
The reason I need it is because I need to make some changes to the object without actually editing the real object.