Javascript get only 10 characters from string

Updated at 01-Oct-2021, By samar

Javascript get only 10 characters from string

With this article, we’ll look at some examples of how to address the "Javascript get only 10 characters from string" problem.

You can get only 10 characters from a string in javascript. You can use in-built substring() method to get the number of specified characters by passing the starting character position and end of last character position including blank space which you want to get.
  • Javascript get only 10 characters from string using substring() method

    <script>
    const string = 'hello, how are you';
    const result = string.substring(0,10);
    console.log(result);
    </script>
    

    Output:

    hello, how

    You can get 10 charater from string in javascript using substring method. The substring() method extracts characters between "start" and "end", like we have pass 0 and 10 in substring() method as start position and end position to get character.

Back to code snippet queries related javascript