6 ms·
"asdf".indexOf("as") is 0 but "asdf"[0] is NOT "as". so there can be no expectation that ""[0] is "". Those two operations are not related to each other. It
by rhn_mk1 3y ago
"asdf".indexOf("as") is 0
but
"asdf"[0] is NOT "as".
so there can be no expectation that ""[0] is "".
Those two operations are not related to each other. It's more intuitive if you treat .indexOf() as .startOf(). Then "asdf"[0..x] is "as" for x=2, and ""[0..x] is "" for x=0.