Answers for "move the last elment to the first position then shift the array"

0

javascript move last array element to first

let arr1 = [1, 2, 3, 4, 5]
let arr2 = [1, 2, 3, 4 ,5]
// first to the last
arr1.push(arr1.shift()) // [2, 3, 4, 5, 1]

// last to the first
arr2.unshift(arr2.pop()) // [5, 1, 2, 3, 4]
Posted by: Guest on June-10-2021
1

move last element of array to begining javascript

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

Code answers related to "move the last elment to the first position then shift the array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language