# \`Array.sortOn()\` does not work as the documentation says it should

**URL:** <https://forum.kirupa.com/t/array-sorton-does-not-work-as-the-documentation-says-it-should/329675>\
**Category:** flash\
**Created:** [October 1, 2012, 4:46am UTC](https://forum.kirupa.com/t/array-sorton-does-not-work-as-the-documentation-says-it-should/329675 "2012-10-01T04:46:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![IQAndreas](https://avatars.discourse-cdn.com/v4/letter/i/f08c70/32.png) [@IQAndreas](https://forum.kirupa.com/u/IQAndreas)\
**Post date:** [October 1, 2012, 4:46am UTC](https://forum.kirupa.com/t/array-sorton-does-not-work-as-the-documentation-says-it-should/329675/1 "2012-10-01T04:46:40Z")

</div>

Just a quick heads up for anyone curious, according to the ASDoc, this is how `Array::sortOn()` is supposed to work:

> If either of the elements being compared does not contain the field that is specified in the fieldName parameter, the field is assumed to be set to undefined, and the elements are placed consecutively in the sorted array in no particular order. _(via [Array::sortOn()](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#sortOn%28%29))_

However, this is not the case!

If you try to sort on a field that does not exist, you get the following error:

```auto
Exception fault: ReferenceError: Error #1069: Property x not found on flash.media.Sound and there is no default value.	at Array$/_sortOn()
	at Array/http://adobe.com/AS3/2006/builtin::sortOn()
	at Testbench/testArraySortOn()[/media/MyBook/Programming/ActionScript/Workspaces/Test Projects/Testbench [2012-07] [FDT]/Testbench/src/Testbench.as:57]
	at Testbench()[/media/MyBook/Programming/ActionScript/Workspaces/Test Projects/Testbench [2012-07] [FDT]/Testbench/src/Testbench.as:14]

```

I’m not sure if it’s a flaw in the documentation, or in the code.
