Hi guys, I just don't seem to get this right at the moment...say I want to create an array of objects, I'd do it this way of course:

arrayOfWords[
    {
        "SearchTerm":"mySearchTerm1",
        "Syn":"synonym1",
        "Syn":"synonym2",
        "Syn":"synonym3"
    },
    {
        "SearchTerm":"mySearchTerm2",
        "Syn":"synonym1",
        "Syn":"synonym2",
        "Syn":"synonym3"
    }   
]

That's all OK but I'm now in a situation where I need to loop through that object, check that the SearchTerm matches the value of another variable declared and set elsewhere and if so I need to loop through the synonyms, so this structure isn't too good because all the elements (SearchTerms and Syn) are on the "same" level: I need to know how many synonyms I have in the array so that I can easily loop through them, so I thought that it might be a good idea to have the synonyms as objects themselves, but I'm having some problems with the syntax, how would I define an array of objects of objects? WOuld it be something like this:

arrayOfWords[
    {
        "SearchTerm":"mySearchTerm1"
            {
                "Syn":"synonym1",
                "Syn":"synonym2",
                "Syn":"synonym3"
            },
        "SearchTerm":"mySearchTerm2",
            {
                "Syn":"synonym1",
                "Syn":"synonym2",
                "Syn":"synonym3"
            }
    }
]

So that each SearchTerm has a number of synonyms?
thanks

Nevermind, I think I figured that out eventually...

dictionary = {"expenses":
    [
        {"Syn":"expenditures"}
    ],
    "paper":
    [
        {"Syn":"study"}
    ],
    "javascript":
    [
        {"Syn":"scripting"}
    ],
    "creating":
    [
        {"Syn":"generating"}
    ]
}
Member Avatar for diafol

Do you need the array [] around the objects?

Member Avatar for diafol

Would this do the same job:

{
    "expenses": {
        "Syn": "expenditures"
    },
    "paper": {
        "Syn": "study"
    },
    "javascript": {
        "Syn": "scripting"
    },
    "creating": {
        "Syn": "generating",
        "Someother": "anything"
    }
}

yes I think that would do as well, sorry for the delay

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.