How to get values from an object without the object name in Javascript
<p>The question sounds weird I know. But its a weird question. Let me clarify.</p>

<p>Im using the facebook graph api. The feeds for my page are returned in JSON and i have this bit of JSON here: </p>

<pre><code>"message": "A3Media Uk Website is fully up and running! Tell your friends, We can't make Beautiful Websites without clients!\n - Alex Morley-Finch",
"message_tags": {
    "116": [
        {
            "id": "514033508",
            "name": "Alex Morley-Finch",
            "offset": 116,
            "length": 17
        }
        ]
    }
</code></pre>

<p>So from my knowledge, there is an object called <code>message_tags</code> which contains and array of objects called <code>116</code>, and index 0 of this array contains and object with the variables <code>id, name, offset and length</code>.</p>

<p>Now what i want to do is, obviously replace the text "Alex Morley-Finch" within the <code>message</code> variable with the tag <code>"name": "Alex Morley-Finch"</code>. Then using the id, length and offset i can replace the text with a html link to that profile using the ID!</p>

<p>This all seem pretty simple, however, i obviously want my code to be dynamic so the code will work for ANY tag at ANY position.</p>

<p>The name of the object array <code>"116"</code> always matches the offset contained inside it.</p>

<p><b> The actual question: </b></p>

<p>How can I dynamically get the name of the object Array (in this case '116')?</p>

<p>Because my code would be something like (pseudo code):</p>

<pre><code>if message has tag
    get name of tag
    if message contains name of tag
        replace message name using offset and length with html link tag with href = facebook url / id
    end if
end if
</code></pre>

<p>This would leave me with my html representation of the "message"</p>

<p>The thing is i cant get the name of the message_tag because id have to do somthing like:</p>

<pre><code>// data[index] represents the current message

var json = JSON.parse(XmlHttpResponse.responseText);
json.data[index].message_tags.116[0].name;
</code></pre>

<p>as we can see this is not dynamic. This code will ONLY work for this tag.</p>

<p><b>So how do i get the name without referencing 116? is it even possible?</b></p>

<p>i was thinking about trying iterating through 1, 2, 3, 4, 5 --> 116 but that would be very performance costly AND bad coding AND im not even sure if you can reference arrays through variable names... ... ...</p>

<p>Im really stumped.</p>

<p>Please Help!</p>

<p>Alex</p>
