so i am having a problem using javascript array splice where it changes the orginal array like
let arr1 = [1,2,3,4,5]
for(i = 0; i < 5; i++){arr1.splice(i,1);}
in this above example , the arr1 gets changed after every iteration like :- [2,3,4,5]...[3,4,5]..etc
what i want to achive is :-
let arr1 = [1,2,3,4,5];
for(i = 0; i < 5; i++){
let arr2 = arr1.splice(i,1);
}
the result of this should give arr1 as [1,2,3,4,5] in all iteration ... but arr2 as [2,3,4,5]...[3,4,5]..etc ..... Basically, i want the splice function to not manipulate the original array but give the result in a new array and the original array remains the same during all iteration... is there any way to do this?