Some of JavaScript-specific object properties are skipped by JSON.stringify.
What are those ?
1. Function properties - means methods
2. Symbolic properties.
3. Properties that store undefined.
However, another good here is, nested objects are supported and converted automatically.
What are those ?
1. Function properties - means methods
2. Symbolic properties.
3. Properties that store undefined.
let user = { sayHi() { // ignored alert("Hello World"); }, [Symbol("id")]: 123, // ignored something: undefined // ignored }; alert( JSON.stringify(user) ); // {} (empty object)
However, another good here is, nested objects are supported and converted automatically.
let testNestedObjects = { title: "NestedCheck", test1: { number: 123, participants: ["test25", "test26"] } }; alert( JSON.stringify(testNestedObjects) ); Output: { "title":"NestedCheck", "test1":{"number":123,"participants":["test25","test26"]}, }
No comments:
Post a Comment