for(var i = 0; i<$scope.notes.length;i++){
if($scope.notes[i].is_important){
var imortant_note = $scope.notes.splice(i,1);
$scope.notes.unshift(imortant_note[0]);//push to front
}
}
how add an element on an array in the beginning on js
In JavaScript, you use the unshift() method
to add one or more elements to the beginning
of an array and it returns the array's
length after the new elements have been added.
example:
var colors = ['white', 'blue'];
colors.unshift('red');
console.log(colors);
// colors = ['red', 'white', 'blue']
var numbers = [2, 3, 4, 5];
numbers.unshift(1);
console.log(numbers);
// numbers: [ 1, 2, 3, 4, 5 ]