Example of the array:
let arr = [
[1, 1, 1, 1],
[2, 2, 2, 2],
[3, 3, 3, 0],
];
I want to be able to move the '0' left, right, up and down.
for example moving the '0' element up:
[
[1, 1, 1, 1],
[2, 2, 2, 0], //<---
[3, 3, 3, 2],
];
I have been able to move the element LEFT and RIGHT with a function as shown below:
function changePosition(arr, from, to) {
arr.splice(to, 0, arr.splice(from, 1)[0]);
return arr;
}
I'd like to some how move the element UP and DOWN. I would appreciate a hand on this code since I haven't found much on the internet.
you can do something like this