["1", "2", "3"].map (parseint) Get what?
The answer is: [1, Nan, Nan].
Cause: parseint receives two parameters, and map passes 3 parameters.
The map function defines :
Arr.map (Callback[,thisarg]);
The callback function requires the following 3 values:
CurrentValue: Current processing value
Index: The indexed value of the numeric value processed
function values handled by the ARRAY:MAP function
Thisarg is optional. The this value in the callback function defaults to the Window object
parseint function Definition:
parseint (stringradix);
String: The character that needs to be converted, if not the string will be converted, ignoring whitespace.
Radix: integer type before the number 2-36. By default, 10 is used, which indicates decimal.
It is important to note that radix returns Nan if it is outside 2-36.
Execute the following function:
var function (String, Radix, others) { return string + '-' + radix + '-' + others;}; [' 1 ', ' 2 ', ' 3 '].map (parseint);
Get:
If you put it in the parseint function:
parseint (' 1 ', 0);p arseint (' 2 ', 1);p arseint (' 3 ', 2);
So get 1,nan,nan
Other uses of the map function:
Example 1: Traversing a Queryselectorall object and executing related functions
var elems = Document.queryselectorall (' div '); var function (elem) { return elem;});
Example 2: Reversing a string
var str = ' 12345 'function(x) { return x;}). Reverse (). Join ();
Attached: This method can judge Palindrome
var str = ' 12345 '; var function (x) { return x;}). Reverse (). Join (); if (str = = = str1) { console.log ('true 'else { console.log (' false ') );}
["1", "2", "3"].map (parseint)?