javascript – Sort Vector Increasingly with Angularjs


$scope.auxiliar.minimo = $scope.blocos[i].tamanhoTotal - processo.tamanho;
$scope.auxiliar.posicaoBlocoLivre = $scope.blocos[i];

I want to sort my "smallest" vector incrementally by the object attribute: "$scope.auxiliar.minimo"


Here's a way to organize the array for use in JS by creating a function to be passed as a parameter in sort.

var sortByMinimo = function(a, b) {
    if (a.minimo < b.minimo) {
        return 1;
    if (a.minimo > b.minimo) {
        return -1;
    return 0;

You can use the AngularJs ways suggested in the other answer, especially if you just want to organize in the view.

Scroll to Top