1//Add element to front of array
2var numbers = ["2", "3", "4", "5"];
3numbers.unshift("1");
4//Result - numbers: ["1", "2", "3", "4", "5"]
1for(var i = 0; i<$scope.notes.length;i++){
2 if($scope.notes[i].is_important){
3 var imortant_note = $scope.notes.splice(i,1);
4 $scope.notes.unshift(imortant_note[0]);//push to front
5 }
6}
1const data= [{code:"001",name:"Kirk-Patrick Brown"},{code:"002",name:"Sara Brown"},{code:"003",name:"Joe Frazer"}];
2
3const firstItem = "003";
4data.sort((x,y)=>{ return x.code === firstItem ? -1 : y.code === firstItem ? 1 : 0; });
5
6console.log(data);