Q:

Angularjs: how to move $index on top of ng-repeat

I would like to move an item of my ng-repeat list in order to make it in first position.
I tried several things, but cannot seems to find a simple solution with orderby filter etc.
here's a fiddle :
http://jsbin.com/xavexepa/3/edit
the goal is to put for example tiger or zebra on the first position at the initialization of the ng-repeat, without sorting anything else

A:

If you just want to move items from one index to another here is an easy solution:
var arr = [
    {
        "name": "dog"
    },
    {
        "name": "cat"
    },
    {
        "name": "mouse"
    }
]

var move = function (array, fromIndex, toIndex) {
    array.splice(toIndex, 0, array.splice(fromIndex, 1)[0] );
    return array;
}

makeItemFirst = function (name){
    for (var i = 0; i < arr.length; i++){
        if (arr[i].name == name){
            arr = move(arr, i, 0);
        }
    }
}

makeItemFirst("mouse");

