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.
What you have there is an E4X XML (or XMLList) object. So do this instead:

```
msg['PID']['PID.13'].children().length()

```