Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business


OverviewFelgo 3 Support (Qt 5) › Can't use "constructor" string in Array or Object


Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #24208


    Sorry for this question, I am a beginner.

    Don’t I know about this?

        function test() {
            const idObj = [{"constructor":"constructor", "home":"home"}]
            const idArr = ["constructor", "home"]
            console.log("results: ", idObj["constructor"], idArr["constructor"])

    I cant use the “constructor” string as object or array value. Output from the code above is:

    results: function Array() { [native code] } function Array() { [native code] }

    Can someone teach me about this?


    Thanks 🙂




    Hi Jufry,

    thank you for reaching out to us and don’t worry, beginner questions are fine.


    Here you’re missing the concepts of JavaScript Arrays and Objects. A JavaScript array is a list of elements that you access by position, while JavaScript Objects are basically key-value pairs. Here’s a few samples:

                    const jsArray = ["a", "b", "c"]
                    console.log(jsArray[0], jsArray[1], jsArray[2]) // prints: a b c
                    const jsObject = { "a": 1, "b": 2, "c": 3 }
                    console.log(jsObject["a"], jsObject["b"], jsObject["c"]) // prints: 1 2 3
                    // You can also have arrays of objects
                    const arrayOfObjects = [{"a": 1}, {"b": 2}, {"c": 3}]
                    // And objects can contain arrays
                    const objectWithArray = { "a": [1, 2, 3] }

    In your example you’re basically treating both as object and trying to access the property with the key “constructor”, which is actually a javascript function.


    Hope this is clear enough to get you started.

Viewing 2 posts - 1 through 2 (of 2 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded