# How to sort an array base on another array?

**URL:** <https://forum.kirupa.com/t/how-to-sort-an-array-base-on-another-array/313614>\
**Category:** Uncategorized\
**Created:** [September 4, 2010, 12:42pm UTC](https://forum.kirupa.com/t/how-to-sort-an-array-base-on-another-array/313614 "2010-09-04T12:42:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayumilove](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ayumilove/32/2532_2.png) [@ayumilove](https://forum.kirupa.com/u/ayumilove)\
**Post date:** [September 4, 2010, 12:42pm UTC](https://forum.kirupa.com/t/how-to-sort-an-array-base-on-another-array/313614/1 "2010-09-04T12:42:23Z")

</div>

I have 2 arrays:  
[6,1,4]  
[“apple”,“pear”,“orange”]

how to sort the fruit array base on the first?  
If the first array was sorted as ascending order:-  
[1,4,6]  
the second array follows the first:-  
[“pear”,“orange”,“apple”]

if it was sorted as descending order:-  
[6,4,1]  
the second one follows the first array order  
[“apple”,“orange”,“pear”]
