Question: I know this has been asked before, but I'm kinda lost here.

I've got an element from which I log the typeof:

```
typeof msg['PID']['PID.13']  // outputs "xml"

```

So following [this answer](https://stackoverflow.com/a/11776835/1650012) I logged the `children.length`, of which I expect it to be a number:

```
typeof msg['PID']['PID.13'].children.length  // also outputs "xml"

```

But the typeof the `children.length` is also `xml`. How can this be?

It's Javascript hidden in a system (Mirth) in which logging is a problem (at least I still haven't found out how it works) so I'm having a hard time debugging this.

Does anybody know how I can get the children count of the element? All tips are welcome!

[EDIT]
As suggested I also tried the output of `msg['PID']['PID.13'].children.length`, but that seems to be empty.

Answer: 
First thing that seems pretty strange to me is: `typeof msg['PID']['PID.13'] // 'xml'`. So, in case you get some xml from the server, you can parse it like so:

```
var parser = new DOMParser(),
    doc = parser.parser.parseFromString(xml, 'text/xml'); //xml is a xml string

typeof doc // 'object'

```

Than, to count the occurrences of some elements/children, you can use xpath:

```
var count = doc.evaluate('count(//someelement)', doc.documentElement, null, XPathResult.NUMBER_TYPE, null).numberValue;

```

You can even run:

```
doc.querySelectorAll('someelement').length

```

and those methods from the comments will work, too:

```
doc.documentElement.children.length

```

So I guess the `xml` object you have in that object is not a real `XMLDocument`, that is why I guess those properties like `msg['PID']['PID.13'].children.length` »seam to be empty«.

**UPDATE**

As pointed out in the answer of @Nick Rupley you might be dealing with an Instance of E4X, and as documented [here](https://developer.mozilla.org/en-US/docs/Archive/Web/E4X), in the **Archive of obsolete content**, it is obsolete in firefox and does not appear at all on [caniuse.com](https://caniuse.com/#search=e4x). So if your code is running in a Browser, you need to change it to one of the variants mentioned above. Otherwise you can find documentation about the usage on the first linked resource on mdn.
So, `msg['PID']['PID.13']` is xml. Can you post it as text here?
If that xml was something like `<children><length><value>5</value></length></children>` then, perhaps, `msg['PID']['PID.13'].children` could have been interpreted by js as if it was `msg['PID']['PID.13']['children']` which is identical js expression. Similarly, dependending on what type of object that is, it could return empty xml node for all invalid nodes, that is:
`typeof msg['PID']['PID.13'].children.a.b.c.d.length`
would also return xml.