Let arr = [27.2, 0, ‘0013’, ’14 px, 123]

arr=arr.map(parseInt);

console.log(arr)


ParseInt ([value]): converts [value] to a string, then searches the left side of the string for all valid characters (the search ends if an invalid numeric character is encountered, regardless of whether there is a number), and converts any found valid numeric characters to numbers. If none is found, the result is NaN. + parseInt([string],[radix]):[radix] is base, valid values range from 2 to 36, default to base 10 if not passed (but defaults to base 16 if characters start with '0x'); If I write 0, it's the same rule as if I didn't write it; + regard [string] as [radix] base system, from do find all characters that conform to this base system, meet the end of the search, find the characters into digits (base 10); + If [radix] is not between 2-36 (exclude 0), NaN is returned; Values of different bases + 2 base 0-1 + 8 base 0-7 + 10 base 0-9 + 16 base 0-9 a-f Convert other base values to base 10 example 1: Let the STR = '12345.23' / / octal converted to decimal 3 * 8 8 ^ ^ 2 + 2 * 1 + 5 * ^ 0 + 4 * 8 August 8 ^ ^ 1 + 3 * 2 + 2 * 8 8 ^ ^ 3 + 1 * 4 = > a decimal value (1/64) + 2 = 3 * * (1/8) + 6 + 32 + 192 + 1024 + 4096 example 2: ParseInt ('0x0BAF3') ->parseInt('0x0BAF3',16) Hexadecimal case insensitive 0x0BAF3 is converted to 10 base 3*16^0+15*16^1+10*16^2+11*16^3+0*16^4 = 10 base value Example 3: ParseInt (0123) =>83 if parseInt('0123'), Let arr= [27.2,0,'0013','14px',123] arr=arr.map(parseInt); Console. log(arr) The arr.map() method takes a callback function as an argument. By default, this callback function is passed two arguments, the current item (item) and the current index (index). The return value of the callback function replaces the current item in the array. Arr.map ((item,index)=>{}) is equal to arr.map(parseInt(item,index)) which returns a new array [parseInt (27.2, 0), parseInt (0, 1), parseInt (' 0013 ', 2), parseInt (' 14 px, 3), parseInt (123, 4)] parseInt (' 27.2 ', 0) = > 27 ParseInt ('0',1) => NaN parseInt('0013',2) =>'001' convert to base 10 parseInt('14px',3) =>'1' convert to base 10 parseInt('123',4) =>'123' converts to base 10 as base 4 (27,NaN,1,1,27)Copy the code