1var colors = ["white","blue"];
2colors.unshift("red"); //add red to beginning of colors
3// colors = ["red","white","blue"]
1//Add element to front of array
2var numbers = ["2", "3", "4", "5"];
3numbers.unshift("1");
4//Result - numbers: ["1", "2", "3", "4", "5"]
1// example:
2let yourArray = [2, 3, 4];
3yourArray.unshift(1); // yourArray = [1, 2, 3, 4]
4
5// syntax:
6// <array-name>.unshift(<value-to-add>);
1// Use unshift method if you don't mind mutating issue
2// If you want to avoid mutating issue
3const array = [3, 2, 1]
4
5const newFirstElement = 4
6
7const newArray = [newFirstElement].concat(array) // [ 4, 3, 2, 1 ]
8
9console.log(newArray);
10
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}