Created
September 5, 2013 11:13
-
-
Save oisinkim/6448824 to your computer and use it in GitHub Desktop.
What to do when JSON.stringify returns cyclic object value
This file contains hidden or 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
| var obj = something; | |
| var res = JSON.stringify(obj, function(key, val) { | |
| if (typeof val == "object") { | |
| if (seen.indexOf(val) >= 0) | |
| return; | |
| seen.push(val) | |
| } | |
| return val; | |
| }) | |
| console.log(res); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment