Is the slice method (string methods) in javascript follow the indexing rule in counting the strings word.

Here is my code var word = "ASDF GHJK L ASDF ASDF GHJK L ASDF ASDF GHJK L ASDF" console.log(word.slice(0,3));

4/16/2019 5:17:56 PM

Not Alive

3 Answers

New Answer


Yes, the "slice" method return new string which represents the part in the string between the start index and the end index (excluding end). In your example it is => "ASD" (without the character in index 3, because it's exclusive). You can read more about "slice" method here: https://www.w3schools.com/jsref/jsref_slice_string.asp


Thanks for some info at the time, i was soo confused that day because of not reading clearly the notes on the books, here is what i did not read. The slice method takes 2 parameters: the start position, and the end position (end not included). I didn't read the last text inside the pair of parentheses , BTW now its all clear thank you, @TheWhiteCat .


Rocket Raccoon, you are welcome 😉