Search code examples
javascriptjsonscopemozillastringify

JSON.stringify doesn't work as expected on changed object. How to handle this?


I have removed my question text, as it didn't address the real error in my code. The two answers fully explain my error, and why I had made it.


Solution

  • The second argument to JSON.stringify is applied recursively, not just at the top level. You're not seeing the "a" property because your basicObjectElements array doesn't contain "a". You will see it if you do this:

    var basicObjectElements = ["changedProperties", "a"];