javascript - Google Chrome cluttering Array generated from .split()
Don't iterate over arrays using for...in
loops!! This is one of the many pitfalls of Javascript (plug) - for...in
loops are for iterating over object properties only.
Use normal for loops instead.
for (var i=0, max = arr.length; i < max; i++) { ... }
Firefox and Safari's ECMAScript/Javascript engines make those particular properties non-enumerable (
{DontEnum}
attribute), so they would not be iterated over in a for...in
loop. Still, for...in
loops were not intended to iterate over array indexes.
For..in
is for iterating over enumerable properties of objects. For an array, to iterate over its indicies, just use a standard for loop
for ( var i = 0, l = arr.length, i < l; i++ ){ // do whatever with arr[i];}
Not directly relevant to this particular problem, but note that splitting strings with regular expressions has all sorts of cross-browser issues. See http://blog.stevenlevithan.com/archives/cross-browser-split for more info, and for solutions.