Just encountered this while posting an answers, and did not figure out why this happens.
Here is the code:
var s = "aaaaaX..";
var a = s.slice(1);
a = a.slice( 0, a.lastIndexOf("X") );
var b = s.slice(1).slice( 0, s.lastIndexOf("X") );
var c = s.slice(1).slice( 0, s.lastIndexOf("X") - 1);
console.log(c);
Why is a not equal to b ?
Why does the -1 have to be added so that c == a ?
sin thes.lastIndexOf("X")refers to the unmodifieds, not thes.slice(1). The.slice()method doesn't mutate the original. EDIT: ...sorry, my original wording was wrong.