0

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

2
Contributors
4
Replies
32
Views
1 Year
Discussion Span
Last Post by Violet_82
0

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

dictionary = {"expenses":
    [
        {"Syn":"expenditures"}
    ],
    "paper":
    [
        {"Syn":"study"}
    ],
    "javascript":
    [
        {"Syn":"scripting"}
    ],
    "creating":
    [
        {"Syn":"generating"}
    ]
}
0

Do you need the array [] around the objects?

0

Would this do the same job:

{
    "expenses": {
        "Syn": "expenditures"
    },
    "paper": {
        "Syn": "study"
    },
    "javascript": {
        "Syn": "scripting"
    },
    "creating": {
        "Syn": "generating",
        "Someother": "anything"
    }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.