World-writable memory on Samsung Android phones
Posted Dec 20, 2012 18:48 UTC (Thu) by
sorpigal (subscriber, #36106)
In reply to:
World-writable memory on Samsung Android phones by apoelstra
Parent article:
World-writable memory on Samsung Android phones
You left out "why"
test is an object of type string, and for a string object you can access characters by indexing into it in a looks-like-C kind of way:
document.write(test[0]); // H
JS for .. in syntax iterates over *keys of an object*
From this you can tell that when I say
test = {one: "hello", two: "world"};
for (i in test) alert(i);
expected this will "one" and "two"
test['two'];
And this will be "World"
The array object is no different, it just has keys that happen to be sequential numbers
test = ['one', 'two'];
for (i in test) alert(i); // 0, 1
alert(test[1]); // two
In order for the string object to look like a C string and let you index characters it must, obviously from the above, appear to store each character at a numeric key corresponding to its index in the string.
The only strange part is why i+1 does string concatenation. I would think that the key would be numeric, but I suppose that there's some reason it isn't. If you need it to be you can use unary +
test = "Hello";
for (i in test) alert(+i+1); // 1, 2, 3, 4, 5 as expected
(
Log in to post comments)