I want object keys to check for duplicates, but I also want to sort the objects later, what should I do?
<p>I have an array called <code>newposts</code></p>

<p>I itterate through it and if it meets certain criteria, I add it to another array:</p>

<pre><code>for (newpost in newposts){
    if (!(  newposts[newpost][0] in currentposts )){
        var triploc1 = locations[newposts[newpost][1]].location;
        var triploc2 = locations[newposts[newpost][2]].location;
        var detour_distance = fourpoint_distance(newloc1, triploc1, triploc2, newloc2);
        if (worthwhile_detour(original_distance,detour_distance)){
            currentposts.push(posts[newposts[newpost][0]])
        }
    }
}
</code></pre>

<p>The second row, is intended to check for duplicates(<code>newposts[newpost][0]</code>) is an ID. When I wrote it I had forgotten that currentposts was an array. Obviously, this doesn't work. I need currentposts to be an array, because just below i sort it. I could ofcourse convert it into an array once the selection is done. But I'm new to javascript and believe someone might know a better way to do this. </p>

<pre><code>function sortposts(my_posts){
    my_posts.sort(function(a, b) {
        var acount = a.sortvar;
        var bcount = b.sortvar;
        return (bcount-acount);
    });

}
</code></pre>
