Sort array based on another array (change order of objects)
<p>I have two Javascript array objects, where first one is sorted in the order I want it to be sorted in and second array is sorted in the wrong order, for example:</p>

<p>1) SortedArray <code>(0 - 10 items, 11 - 20 items, 21 - 30 items, 10000 - 20000 items)</code></p>

<p>2) Alphabetically sorted Array <code>(0 - 10 items, 10000 - 20000 items, 11 - 20 items, 21 - 30 items)</code></p>

<p>I would like to sort the second array in the same order as the first one, is there an easy way to solve this issue?</p>

<p>Any help would be appreciated. Thank you.</p>

<p><strong>Conditions:</strong></p>

<p>1) The second array can be different in size. So it could have less values than the first array.</p>

<p>2) If the data is corrupt, the second array can have values that do not exist in the first array.</p>

<p><strong>Update</strong></p>

<p>I have built an sample here based on Bergi's response: jsfiddle.net/EPwS6 - but now I need to figure out how I can preserve values in arr2 which do not exist in arr1. Any ideas or tips?</p>
