I have the function below to "clone" an object. Occasionally we see an "Invalid character" error message displayed in the browser's console. Based on the documentation for the JSON object, this function should work flawlessly. I also checked, and the objects being serialized do not implement the toJSON() function. What kind of object(s) would cause this error?
function deepCopy (obj) {
return JSON.parse(JSON.stringify(obj));
}
Update: It appears to only happen with IE11.
JSON.parseno need ofJSON.stringifyobj?JSON.stringify(undefined)returns undefined instead of a string. That might be it.