So I have a JavaScript array going somewhat like
- screw cap bottle [tech.]
- nonreturnable bottle magnum empty
- tank
- diving magnetic bottle [tech.]
- unbreakable bottle
- full
- tank
- diving
- Stuff (5 of 5)
- eine Flasche austrinken ein Baby mit
- der Flasche ernähren ein Baby mit
- der Flasche füttern mit der Flasche
- aufziehen
My problem is the element "Stuff (5 of 5)". Basically, I dont want this to appear in the array. It wouldnt be a big problem if the was always the same, but the array is generated dynamically and the numbers behind differ. So, for example, on time it is "Stuff (2 of 3)", another time "Stuff (6 of 6)" and so on and so on. The first part stays the same.
So I thought Regular Expressions would solve the problem as thats what they actually are for. So I hacked together this code:
var regExpStuff = /Stuff\b/;
var array = removeItem(unique, regExpStuff);
The function removeItem() looks like this:
//remove item (string or number) from an array
function removeItem(originalArray, itemToRemove) {
var j = 0;
while (j < originalArray.length) {
if (originalArray[j] == itemToRemove) {
originalArray.splice(j, 1);
} else { j++; }
}
return originalArray;
}
The function works fine with simple strings like "string", but it doesn't this way.
Any ideas what could be wrong? Help is highly appreciated,
Benny