Answers for "move element to the top of list javascript"

1

javascript move array element to front

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
	}
}
Posted by: Guest on January-02-2020
0

move element to the top of list javascript

const data= [{code:"001",name:"Kirk-Patrick Brown"},{code:"002",name:"Sara Brown"},{code:"003",name:"Joe Frazer"}];

const firstItem = "003";
data.sort((x,y)=>{ return x.code === firstItem ? -1 : y.code === firstItem ? 1 : 0; });

console.log(data);
Posted by: Guest on September-07-2020

Code answers related to "move element to the top of list javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language