I have an array something like this:
[
{id: 5, attr: 99},
{id: 7, attr: null},
{id: 2, attr: 8},
{id: 9, attr: 3},
{id: 4, attr: null}
]
What would be the most efficient to put all objects with attr === null
at the beginning of the array, without changing order of other elements in the array? (e.g. I need ids to go in this order: 7, 4, 5, 2, 9 (the order of 7 and 4 don't matter, but the order of 5, 2, 9 must never change.)
Simple fiddle to test your code: http://jsfiddle.net/8GEPC/