I am trying to create a way to move items between two boxes.
I fill the left box with items. When clicking on a item, it moves to the right box.
I can fill the left box with several items that I can move.
If I have already moved a item from the left, I should not see that item anymore in the left box.
To do this. I have made a removeDuplicate() from the left box array.
But I have a fault that makes one item to accour on i the left box even if I have it in the right box.
I made a JSFiddle to demonstrate the problem.
If you click three items from Item_01, the select three items from Item_02. This makes six items in the right box. If you go back to Items_01. The three items you selected earlier should not be in the lefyt box now. But as you can see, one of those three are still there.
So my removeDuplicate() does not work. And I can't figure out why.
I really need help.
function removeDuplicates() {
//alert("klick");
for(var i=0; i < arrItems.length; i++) {
for(var j=0; j < arrSelectedItems.length; j++) {
if(JSON.stringify(arrItems[i]) == JSON.stringify(arrSelectedItems[j])) {
arrItems.splice(i, 1);
}
}
}
}
Response to suggestion about this question being a same as another question. This is not the same because I do not want to create a new array. I want to remove duplicate in exsisting array.