Methods to keep only First N characters in a String
Table of Content
- Using substring() Method
- Using slice() Method
- Using JavaScript For loop
- Using String’s substr() Method
JavaScript to keep only first N characters in a string
In this article, we have given a string and the task is to keep only the first n characters of the string using JavaScript. There are various methods to solve this problem, some of which are discussed below: