Display objects from an array in order, depending on an specific value
<p>i have this json:</p>

<pre><code>var projects_array = [
{name:"proj1", category:"a", index:1},

{name:"proj2", category:"a", index:2},

{name:"proj3", category:"b", index:3},  

{name:"proj4", category:"c", index:4}
];
</code></pre>

<p>I am displaying them in order with something like this:</p>

<pre><code>for (var i = 0 ; i &lt;proj_num; i++){ 
var numClass="p_"+projects_array[i].index;  
    var act="&lt;li class='"+numClass+"'&gt;&lt;/li&gt;";           
$('#lookfor').append(act);             
}
</code></pre>

<p>What i need now is to display first all the objects with the value "a" in the category attribute and then all the other objects in any order, i tried using .sort() in this way:\</p>

<pre><code> function compare(obj){
if(obj.category == "a"){ return 1;}                 
    else{return 0;}                     
}                       
obj.sort(compare);
</code></pre>

<p>But it does not worked because it kind of group all the objects of the category...</p>

<p>do you have any possible solution for this problem?</p>

<p>ps: I tried to simplify my code to make it understandable, i hope it be clear for you, thanks in advance</p>
