JSON.stringify() accepts a second parameter called "the replacer parameter". This parameter can be:
An array: the values in the function represent which keys of the object should be stringifyed into JSON. Anything not in the array is left out of the JSON string.
A function: the function accepts 2 parameters - key and value. The return value of this function is what will be inserted into the JSON object for the given key. Returning undefined omits the key from the JSON object. This allows you to provide custom logic when stringifying objects to JSON
JSON.stringify() accepts a second parameter called "the replacer parameter". This parameter can be:
An array: the values in the function represent which keys of the object should be stringifyed into JSON. Anything not in the array is left out of the JSON string.
A function: the function accepts 2 parameters - key and value. The return value of this function is what will be inserted into the JSON object for the given key. Returning undefined omits the key from the JSON object. This allows you to provide custom logic when stringifying objects to JSON