Tip #45[JSON replacer]

If you want to serialize a JavaScript object, the built-in JSON.stringify function allows you to accomplish the goal. The function ignores methods, symbolic properties and the ones with undefined value:

However, you can get more control over the process and exclude additional properties from being serialized with the aid of the replacer function passed as the second argument to the JSON.stringify method. It’s invoked with key and value of each property. If you want to skip it, you need to return undefined, otherwise return a given property’s value:

Live example:

If you like the tip, please give me some applause 👏

--

--