Created
May 3, 2021 07:39
-
-
Save melvinstanly/e59ba97571ca7fb05a888b356524ee81 to your computer and use it in GitHub Desktop.
JSON.stringify returns []
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
function json_encode(){ | |
var content = []; | |
content.field1 = { width: "100px", height: "400px", label : "Width"}; | |
content.field2 = { width: "200px", height: "500px", label : "Height"}; | |
console.log(JSON.stringify(content)); | |
} | |
// The above function return [] because the key used here is a string. | |
//The array key should be integer for JSON.stringify to return proper value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment