showing results for - "javascript remove leading zeros from string"
Ricardo
06 Aug 2016
1use a regular expression like this  
2
3var strNumber = "0049";  
4console.log(typeof strNumber); //string  
5  
6var number  = strNumber.replace(/^0+/, ''); 
Elena
30 Apr 2017
11. Using substring()
2The substring() method returns the part of the string between the specified indexes, or to the end of the string.
3
4let str = 'Hello';
5 
6str = str.substring(1);
7console.log(str);
8 
9/*
10    Output: ello
11*/
12 
13The solution can be easily extended to remove first n characters from the string.
14
15
16let str = 'Hello';
17let n = 3;
18 
19str = str.substring(n);
20console.log(str);
21 
22/*
23    Output: lo
24*/
25 
26___________________________________________________________________________
272. Using slice()
28The slice() method extracts the text from a string and returns a new string.
29
30let str = 'Hello';
31 
32str = str.slice(1);
33console.log(str);
34 
35/*
36    Output: ello
37*/
38 
39This can be easily extended to remove first n characters from the string.
40
41
42let str = 'Hello';
43let n = 3;
44 
45str = str.slice(n);
46console.log(str);
47 
48/*
49    Output: lo
50*/
51 
52__________________________________________________________________________
533. Using substr()
54The substr() method returns a portion of the string, starting at the specified index and extending for a given number of characters or till the end of the string.
55
56
57let str = 'Hello';
58 
59str = str.substr(1);
60console.log(str);
61 
62/*
63    Output: ello
64*/
65 
66Note that substr() might get deprecated in future and should be avoided.
queries leading to this page
javascript add leading zeros to string after trimmingjavascript parseint not remove leading 0javascript function to removing leading zeoesremove leading spaces in jsremove leading zeros javascriptjs remove leading and trailing slashadd trailing 0 to end of string javascriptremove leading zeros in node jsremove leading zeros in javascripthow to trim leading zero string in javascriptget rid of leading zeros in jsremove leading zeros from decimal javascriptremove leading zeros from not number string jsjs remove leading zeroes from a stringremove leading and trailing zeros javascripthow to remove trailing and leading zeros in javascriptjavascript remove a leading 0 if there is onejavascript string remove leading zeroshow to remove leading zeros from time in javascriptremove leading and trailing characters in jsremove leading 0 from number javascripthow to remove leading zeros from number in javascriptremove leading and trealing space jsjavascript remove leading line breaksjavascript add zeros trim charactershow to remove starting 0 from number javascriptremove leading 0 in jshow to remove leading 0 in a number javascripttrim leading zeros javascripthow to remove leading space in javascriptjavascript trim leading zeros mirthjs string remove leadingremove leading zero from string jstrim leading spaces in javascriptconvert a string to number but removing zeros in javascriptremove leading zeros jsignore leading zeros jshow to preserve leading zeros in javascripthow to cut off leading bit zero in javascriptreplace leading zeros in javascriptjs remove leading zero from stringremove leading character from string in javascriptremove leading 0 in js numberhow to remove leading zeros from date in jsremove zeros after decimal in javascripthow to remove leading zeros javascriptjavascript remove leading zeros from numberhow to convert string into number without removing leading zero jsjavascript remove leading zeroesjavascript string trim leading zeroshow to delete leading zero from string in javascriptremove leading 0 from string javascriptdelete leading zeros jsremove leading 0 jsremove leading space javascript stringremove leading zero in javascripthow to remove starting zeros in javascriptremove trailing zeros from number javascriptremove trailing zeros javascript from stringjs remove leading 0sremove zeros after decimal javascriptjavascript remove leading zeros on input type 3dnumberremove leading spaces from string javascriptremove leading 0 from number javascriptremove leading zero javascriptadd trailing zeros javascriptjavascript remove leading zero if next character isn 27t decimal pointremove zeros from number javascriptremove leading character from number in javascriptjavascript remove leading zeros from number and get decimaljs string remove leading zerosjavascript remove leading zeros and get decimalremove leading zero from a number javascripttolocaletimestring js remove leading 0sjavascript removing leading zero monthjavascript trim leading zeroshow to filter leading and trailing zeros from array javascripti want to remove leading zeroes in a string jsstrip leading zeros javascriptjs remove leading zerosremove leading zeros from string javascriptjs remove leading zeros from stringremove leading 0 javascriptremove leading zeros padding javascriptjs remove leading 0remove trailing zeros from string javascriptremove zero before number javascriptjs trim leading zerosremove leading 0s javascripthow to delete leading zero from input text in javascriptremove leading 0 from javascriptjs remove leading 1javascript remove leading characterhow to remove leading zeros from a string in javascriptjavascript remove leading spacesjavascript remove leading zeroeliminate the leading zero in js when rendered in browserwhy does changing an int to a string erase leading 0s javascriptjavascript trim leading spaceleading zeroes removing in string jsremove leading spaces javascriptjs remove leading and trailing zerosnumber get rid of the leading zeros jqueryjavascript remove trailing zeros from stringremove leading character nodejavascript leading zeros removejavascript to remove zeros in front of numberjavascript remove leading zeros from stringjavascript remove leading 0 from floatjavascript 22add leading zeros 22 to string after trimminghow to remove leading zero in a string in javascriptjavascript why removed leading zeros automaticalljavascript remove leading zerosremove trailing zeros from integer javascriptadd trailing zeros in javascriptregex remove leading zeros javascripthow to trim leading zeros in javascriptremove leading plus from number in javascripthow to remove leading zeros from time format in javascriptremove all leading and trailing spaces in javascriptremove preceding zeros in js stringtrailing and leading zeros javascript removejavascript remove leading 0 from stringremove leading zero float jshow to remove leading plus sign in javascriptremove leading and trailing zeros from array javascripthow to remove leading zeros in javascriptjs remove leading spacesjavascript string remove leading spacesremove starting zero from string in jshow to delete leading zero from string in javascript onchangejavascript remove leading trailingremove zeros from number in javascriptjs delete leading 0remove leading zeros from a number in javascriptremove leading zero jsremove leading 5cn jsjavascript to remove leading zerosjavascript remove leading zeros from arrayjavascript is remove leading zeros automaticallremove leading characters in javascriptjavascript remove leading commajavascript remove leading zero from numberjavascript remove leading zeros from string