Question: This is probably a very easy question but let's say I have a php json\_encoded javascript object of this form:

```
var js_objet = {
    "1": {
        "Users": {
            "id": "14",
            "name": "Peter"
         }, 
         "Children": [
             {
                 id: 17, 
                 name: "Paul"
             }, 
             {
                 id: 18, 
                 name: "Mathew"
             }
        ]
      }    
    }

```

What is the synthax to get the name of the child with id 18 (Mathew) for example from that Object?

Thank you

Answer: 
Here's such a custom function as mentioned earlier.

```
function getChildrenById(id){
    for (var child in js_objet[1].Children){
        if(id == js_objet[1].Children[child].id){
            return js_objet[1].Children[child].name;
        }
    }
    return false;
}

```

running `getChildrenById(18)` would return "Mathew"

Hope that helps,

R.
This is how I would approach this problem:

```
var id = 18;
var name = '';
var jsObjIndex = "1";
var jsObjAttr = "Children"
for (var i = 0; i < js_objet[jsObjIndex][jsObjAttr].length; i++)
{
    if (js_objet[jsObjIndex][jsObjAttr][i].id == id)
    {
        name = js_objet[jsObjIndex][jsObjAttr][i].name;
        break;
    }
}

```

You are basically performing a linear search on every element of jsObjIndex.Children. There are likely better solutions however :).