var obj = [ "one", "two", "three"];
$.each(obj, function() {
console.log(this);
});
The output I get is
{ '0': 'o', '1': 'n', '2': 'e' }
{ '0': 't', '1': 'w', '2': 'o' }
{ '0': 't', '1': 'h', '2': 'r', '3': 'e', '4': 'e' }
I suppose to get “one” “two” “three”, but I get the following weird results, anyone can explain?
thisis always an object there. A string object consists of key/value pairs where keys are indices and values are characters at that index in the string. TryObject("foo")to create such an object yourself.By using strict mode you can suppress that: