In this case, to return the first "s" of "saints", you would have to define the second argument with -5
:
var name = "maria mendonça maria maria dos santos";
console.log(name.slice(-6, -5));
And to return "saints", it would be enough to omit the second argument:
var name = "maria mendonça maria maria dos santos";
console.log(name.slice(-6));
Because then it will pick up from the 6th character to the end of the string, backwards. The value 0
is not applicable in the second argument.
If you want to take the second "s" -1
:
var name = "maria mendonça maria maria dos santos";
console.log(name.slice(-1));
When you want to use negative value, you will not use the indices of the string, only the position backwards starting from number 1 up, negatives:
var name = "maria mendonça maria maria dos santos";
// de trás pra frente:
s = -1
o = -2
t = -3
n = -4
a = -5
s = -6
...
Of which "s" in sbirthdays you’re talking?
– bfavaretto