

slice() which will simply return an empty string. substring() will swap the two parameters. substring() is negative, it’s treated as zero. ( /en-US/docs/Web/JavaSc.) is very similar to. slice() starts from the end of the string and works backwards. This works because when startIndex is negative. Instead of writing RIGHT('The quick brown fox', 3), you can write… 'The quick brown fox'. Instead of writing LEFT('The quick brown fox', 3), you can write… 'The quick brown fox'. I like using LEFT() and RIGHT() in other languages slice() will simply return characters all the way to the end of the string. It may be helpful to think of an “index” as the spaces between characters, starting at zero.ĮndIndex is optional. ( /en-US/docs/Web/JavaSc.) takes two parameters.īeginIndex - The index of the first character to returnĮndIndex - The index of the last character to return Which one should you use? The answer may depend on the context of your problem, but in the interest of keeping things simple, I say just use.

In JavaScript, there are three prototype methods for getting part of a string.
