A slice(begin, end) method works on strings, as well as arrays. It returns a string representing the substring of the original string, from beginning to end (end not included) where to begin and to end represent the index of characters in that string.
Let’s see HTML example code:
<html> <body> <script> var str = "Hello world, Simple example"; var strFirstThree = str.substring(0,3); console.log(strFirstThree); </script> </body> </html>
Do comment if you have any doubts and suggestions on this JS char topic.
Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version