How do I preserve undefined values when doing JSON.stringify(hash)?
Here\'s an example:
var hash = {
\"name\" : \"boda\",
\"email\" : undefined,
You can pass a replacer function to JSON.stringify to automatically convert undefined values to null values, like this:
var string = JSON.stringify(
obj,
function(k, v) { return v === undefined ? null : v; }
);
This works for undefined values inside arrays as well, as JSON.stringify already converts those to null.