home ~ projects ~ socials

Strip The First N Number Of Characters Off A String In JavaScript

const value = "alfa-bravo";
const updated = value.slice(4);

Notes

  • Using .slice() over .substring() because .slice() can use negative numbers (need to test if .substring() can as well
  • Both .slice() and .substring() can have ending index as well (e.g. .slice(3, 5))
-- end of line --

References