Let's say I have an array of objects and one of the properties of each object is TheID. Something like this:
TheArray[0].TheID = 34;
TheArray[1].TheID = 2352;
...
I'm looking to return the index of the array that contains the property TheID I'm looking for.
I have a classic for-loop:
for (i = 0; i < TheArray.length; i++) {
if (TheArray[i].TheID = MagicNumber) { var TheIndex = i; }
}
retun TheIndex;
This works but it still has to loop through the entire array, even after it found TheIndex.
How do you stop the loop after the it found TheIndex?
Thanks.