xxxxxxxxxx
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
}
}
xxxxxxxxxx
function moveItemToFirst(array, index) {
if (index >= array.length || index < 0) {
return array; // If index is out of bounds, return the array as is
}
const item = array.splice(index, 1)[0]; // Remove the item from the array
array.unshift(item); // Add the item back at the beginning of the array
return array;
}
// Example usage:
const originalArray = [1, 2, 3, 4, 5];
const newArray = moveItemToFirst(originalArray, 3);
console.log(newArray); // Output: [4, 1, 2, 3, 5]
xxxxxxxxxx
//Add element to front of array
var numbers = ["2", "3", "4", "5"];
numbers.unshift("1");
//Result - numbers: ["1", "2", "3", "4", "5"]
xxxxxxxxxx
let first = "role";
data.sort(function(x,y){ return x == first ? -1 : y == first ? 1 : 0; });