Top community members
All Wiki Articles Create Wiki Article

Many years me and my friends we were volunteers on my university doing programming classes for young people.

I got main conclusion: Young people are awesome, especially students, because they always bring new and fresh ideas :)
* I loved to do it but my time is limited

  I decided to create something that will help millions of students

Now I am here


JavaScript - remove first n characters from string - js util

0 contributions
17 points

In JavaScript it is possible to remove first n characters from string in following way.

1. Using String slice() method

// ONLINE-RUNNER:browser;

// remove first n characters from string
function removeFirstChars(text, n) {
    return text.slice(n);

console.log( removeFirstChars('12345', 0) ); // 12345
console.log( removeFirstChars('12345', 1) ); // 2345
console.log( removeFirstChars('12345', 2) ); // 345
console.log( removeFirstChars('12345', 3) ); // 34
console.log( removeFirstChars('12345', 4) ); // 5

// below results are empty, that's why we compare them to ''
console.log( removeFirstChars('12345', 5) === '' ); // true

We can achieve the same results using:

  • String substring() method
  • String replace() method
0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more