How to console log a JS object
-
I have an empty property as
property var cycleOptionsAllowed: ({})
and I am able to add values to it by doing something likecycleOptionsAllowed["data"] = ["some", "data"]
.As far as I know this is a JS object, so if I use
console.log(JSON.stringify(cycleOptionsAllowed))
I get an output as[]
instead of showing{"data": ["some", "data"]}
.What am I doing wrong here?
Update:
But when I do
for (var p in cycleOptionsAllowed){ console.log("hello key", p) }
I get all the keys in it
I am using Qt 6.2
-
@AkshayFP said in How to console log a JS object:
This is so weird. I am not sure why I am not able to print it.
Try creating a new, blank project and test it there.
I'm guessing your original code has something like
cycleOptionsAllowed = []
somewhere. -
I have an empty property as
property var cycleOptionsAllowed: ({})
and I am able to add values to it by doing something likecycleOptionsAllowed["data"] = ["some", "data"]
.As far as I know this is a JS object, so if I use
console.log(JSON.stringify(cycleOptionsAllowed))
I get an output as[]
instead of showing{"data": ["some", "data"]}
.What am I doing wrong here?
Update:
But when I do
for (var p in cycleOptionsAllowed){ console.log("hello key", p) }
I get all the keys in it
I am using Qt 6.2
@AkshayFP said in How to console log a JS object:
I have an empty property as
property var cycleOptionsAllowed: ({})
and I am able to add values to it by doing something likecycleOptionsAllowed["data"] = ["some", "data"]
.As far as I know this is a JS object, so if I use
console.log(JSON.stringify(cycleOptionsAllowed))
I get an output as[]
instead of showing{"data": ["some", "data"]}
.What am I doing wrong here?
...
I am using Qt 6.2
Works for me on Qt 6.2.4 (MSVC 2019)
Code
property var cycleOptionsAllowed: ({}) Component.onCompleted: { cycleOptionsAllowed["data"] = ["some", "data"] console.log(JSON.stringify(cycleOptionsAllowed)) }
Output
qml: {"data":["some","data"]}
-
This post is deleted!
-
@AkshayFP said in How to console log a JS object:
I have an empty property as
property var cycleOptionsAllowed: ({})
and I am able to add values to it by doing something likecycleOptionsAllowed["data"] = ["some", "data"]
.As far as I know this is a JS object, so if I use
console.log(JSON.stringify(cycleOptionsAllowed))
I get an output as[]
instead of showing{"data": ["some", "data"]}
.What am I doing wrong here?
...
I am using Qt 6.2
Works for me on Qt 6.2.4 (MSVC 2019)
Code
property var cycleOptionsAllowed: ({}) Component.onCompleted: { cycleOptionsAllowed["data"] = ["some", "data"] console.log(JSON.stringify(cycleOptionsAllowed)) }
Output
qml: {"data":["some","data"]}
-
@AkshayFP said in How to console log a JS object:
This is so weird. I am not sure why I am not able to print it.
Try creating a new, blank project and test it there.
I'm guessing your original code has something like
cycleOptionsAllowed = []
somewhere.