diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 79c8d07934..c6c4f187d0 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -82,7 +82,7 @@ OpenLayers.Util.extend = function(destination, source) { * {Array} A reference to the array */ OpenLayers.Util.removeItem = function(array, item) { - for(var i=0; i < array.length; i++) { + for(var i = array.length - 1; i >= 0; i--) { if(array[i] == item) { array.splice(i,1); //break;more than once?? diff --git a/tests/test_Util.html b/tests/test_Util.html index 9b23b5d6bb..171a02fe5e 100644 --- a/tests/test_Util.html +++ b/tests/test_Util.html @@ -12,12 +12,14 @@ } function test_03_Util_Array(t) { - t.plan( 1 ); + t.plan( 2 ); - var array = new Array(1,2,3,4,5); + var array = new Array(1,2,3,4,4,5); OpenLayers.Util.removeItem(array, 3); - t.eq( array.toString(), "1,2,4,5", "Util.removeItem works"); + t.eq( array.toString(), "1,2,4,4,5", "Util.removeItem works on one element"); + OpenLayers.Util.removeItem(array, 4); + t.eq( array.toString(), "1,2,5", "Util.removeItem works on more than one element "); } function test_03_Util_pagePosition(t) {