optimized way to sort array of objects in order of another array values in javascript : <p>I have a array of ids and array of objects.  </p>

<pre><code>var ids = [4, 2, 5, 8]
var objs = [
            {"id": 2, "name": "a"}, 
            {"id": 4, "name": "b"}, 
            {"id": 8, "name": "c"}, 
            {"id": 5, "name": "d"}
        ]
</code></pre>

<p>I want to sort <code>objs</code> in order of values given in <code>ids</code> array.<br>
so sorted objs should be   </p>

<pre><code>[
    {"id": 4, "name": "a"}, 
    {"id": 2, "name": "b"}, 
    {"id": 5, "name": "c"}, 
    {"id": 8, "name": "d"}
]
</code></pre>
