For in loop with index value

I'm familiar with the for in loop in javascript

for (i in Array)
   {
   //do stuff with i
   }

What about if we want to find the index and destroy it?

for (index => value in Array)
   {
   //do stuff with i
   if(value stuff)
      {
      myArray.RemoveAt(index);
      }
   }

Would I have to resort to the for i++ Array.length and then use the i? In my case I think that would work, but if it was a key array it wouldn't.

I hope that makes sense

Thanks, Peter

I don't know about JavaScript, but in C#, you cannot modify a collection as you're enumerating it.

So this code is not valid:


foreach(string s in MyStringList)
{
     MyStringList.Remove(s); // throws an exception
}

So yes, you will have to use a regular for loop (not foreach) to enumerate your array/collection, and I believe the same applies to Javascript (since it's all compiled down to Mono anyway).