Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to console log a JS object
Forum Updated to NodeBB v4.3 + New Features

How to console log a JS object

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qml
5 Posts 3 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AkshayFP
    wrote on 16 Sept 2022, 04:34 last edited by AkshayFP
    #1

    I have an empty property as property var cycleOptionsAllowed: ({}) and I am able to add values to it by doing something like cycleOptionsAllowed["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

    J 1 Reply Last reply 16 Sept 2022, 07:05
    0
    • A AkshayFP
      23 Sept 2022, 00:29

      @JKSH This is so weird. I am not sure why I am not able to print it.

      J Offline
      J Offline
      JKSH
      Moderators
      wrote on 23 Sept 2022, 01:51 last edited by
      #5

      @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.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • A AkshayFP
        16 Sept 2022, 04:34

        I have an empty property as property var cycleOptionsAllowed: ({}) and I am able to add values to it by doing something like cycleOptionsAllowed["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

        J Offline
        J Offline
        JKSH
        Moderators
        wrote on 16 Sept 2022, 07:05 last edited by
        #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 like cycleOptionsAllowed["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"]}

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        A 1 Reply Last reply 23 Sept 2022, 00:29
        4
        • P Offline
          P Offline
          petulantnonce
          Banned
          wrote on 20 Sept 2022, 02:13 last edited by petulantnonce
          #3
          This post is deleted!
          1 Reply Last reply
          0
          • J JKSH
            16 Sept 2022, 07:05

            @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 like cycleOptionsAllowed["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"]}

            A Offline
            A Offline
            AkshayFP
            wrote on 23 Sept 2022, 00:29 last edited by
            #4

            @JKSH This is so weird. I am not sure why I am not able to print it.

            J 1 Reply Last reply 23 Sept 2022, 01:51
            0
            • A AkshayFP
              23 Sept 2022, 00:29

              @JKSH This is so weird. I am not sure why I am not able to print it.

              J Offline
              J Offline
              JKSH
              Moderators
              wrote on 23 Sept 2022, 01:51 last edited by
              #5

              @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.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0

              1/5

              16 Sept 2022, 04:34

              • Login

              • Login or register to search.
              1 out of 5
              • First post
                1/5
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved