从数字字符串中删除所有前导零

问题描述:

我有以下情况:


  1. 09189898989

  2. 00898989899

我想使用JavaScript从字符串中删除所有前导零

I want to remove all leading zeros from the string using JavaScript

什么是最好的方法完成这个?

What is the best way to accomplish this?

您可以使用正则表达式匹配字符串开头的零:

You can use a regular expression to match the zeroes at the beginning of the string:

str = str.replace(/^0+/, '');