javascript - Google Chrome cluttering Array generated from .split()
Posted
by patrick
on Stack Overflow
See other posts from Stack Overflow
or by patrick
Published on 2010-05-26T15:58:01Z
Indexed on
2010/05/26
16:01 UTC
Read the original article
Hit count: 122
Given the following string:
var str = "one,two,three";
If I split the string on the commas, I normally get an array, as expected:
var arr = str.split(/\s*,\s*/);
Trouble is that in Google Chrome (for Mac), it appends extra properties to the array.
Output from Chrome's debugger:
arr: Array
0: one
1: two
2: three
constructor: function Array()
index: undefined
input: undefined
length: 3
So if I iterate over the array with a for/in
loop, it iterates over the new properties. Specifically the input
and index
properties. Using hasOwnProperty
doesn't seem to help.
A fix would be to do a for
loop based on the length of the Array. Still I'm wondering if anyone has insight into why Chrome behaves this way. Firefox and Safari don't have this issue.
© Stack Overflow or respective owner