How to hide few keys from JSON stringification

Hello Reader,
Sorry for blogging after really long time. Here is something interesting.

JSON stringify generally try to stringify every thing deeply in an object. There is a formal way to skip (of hiding) something from being stringified. Just use the second argument on stringify function.

There is a easy and hidden trick to hide few keys. Which works like this.

1. Create a variable and assign an empty array. This makes object to be the prototype of array. 
2. Add non numeric keys on this object. 
3. Serialize this object using JSON.stringify
4. You will see that nothing is serialized from this object. 

See It here,output

No comments:

Post a Comment

Your comment will inspire me, Please leave your comment