# Array - Sort()

**URL:** <https://forum.kirupa.com/t/array-sort/226148>\
**Category:** flash\
**Created:** [May 18, 2007, 1:42pm UTC](https://forum.kirupa.com/t/array-sort/226148 "2007-05-18T13:42:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dom4j](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@Dom4j](https://forum.kirupa.com/u/Dom4j)\
**Post date:** [May 18, 2007, 1:42pm UTC](https://forum.kirupa.com/t/array-sort/226148/1 "2007-05-18T13:42:10Z")

</div>

this is something i really want help with cause i don’t really understand any of the ‘Array’ functions. any way, i have made homing missiles in flash, but i want to make them ‘pick’ their targets acording to distance from the missile to the target. here is what im currently using:

function findTarget(obj) {  
for (i=0; i\<Targets.length; i++) {  
xdif = obj.\_x-Targets\*.\_x;  
ydif = obj.\_y-Targets\*.\_y;  
targetDis\* = Math.sqrt(xdif_xdif+ydif_ydif);  
}  
targetDis.sort();  
findRot(obj, Targets[eval(targetDis[0])].\_x, Targets[eval(targetDis[0])].\_y);  
}

this function would be called from inside the missile like this: findTarget(this)

what exactaly does sort() and what should i use for my homing missiles?

thanx Heaps

Dom
