Last active
April 12, 2022 10:56
-
-
Save bitsandbytes/03766c6ed646ea3737b02b7fc76f3d52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# easy way to remove circular references when stringifying | |
var cache = []; | |
JSON.stringify(o, function(key, value) { | |
if (typeof value === 'object' && value !== null) { | |
if (cache.indexOf(value) !== -1) { | |
// Circular reference found, discard key | |
return; | |
} | |
// Store value in our collection | |
cache.push(value); | |
} | |
return value; | |
}); | |
cache = null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment