当前位置:网站首页>Application of map function in JS

Application of map function in JS

2022-06-23 03:05:00 It workers

map function

Let's first review ,map First argument to function callback:

var new_array = arr.map(function callback(currentValue[, index[, array]]) { 
// Return element for new_array
 }[, thisArg])

This callback You can receive three parameters , The first parameter represents the element being processed , The second parameter represents the index of the element .

parseInt function

parseInt Cardinality is a value between 2 and 36 Integer between .

parseInt(string, radix)
// Receive two parameters , The first represents the value being processed ( character string ), The second is the cardinality of parsing .

Simulation

After understanding these two functions , We can simulate the operation .

parseInt('1', 0) //radix by 0 when , And string Parameter is not in “0x” and “0” At the beginning , according to 10 Processing for cardinality . This time back 1
parseInt('2', 1) // The base number is 1(1 Base number ) In the number represented by , Less than the maximum 2, So I can't parse , return NaN
parseInt('3', 2) // The base number is 2(2 Base number ) In the number represented by , Less than the maximum 3, So I can't parse , return NaN

map Function returns an array , So the end result is [1, NaN, NaN]

原网站

版权声明
本文为[It workers]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/01/202201242154044634.html