当前位置:网站首页>JS interview collection test question 1
JS interview collection test question 1
2022-07-02 04:52:00 【Magic hope】
// Find the output
console.log(['1','2','3'].map(parseInt))
JavaScript map() Function USES
One 、 Concept
map()
Method defined in JavaScript OfArray
in , It returns a new array , The elements in the array are the values processed by the original array call function .
Be careful :
map()
Empty arrays are not detectedmap()
It doesn't change the original array
Two 、 Parameter description :
array.map(function(currentValue, index, arr), thisIndex)
function(currentValue, index, arr)
: must . For a function , Every element in the array performs this function . Where function parameters :
currentValue
: must . The value of the current element .index
: Optional . Index of the current element .arr
: Optional . The array object to which the current element belongs .
thisValue
: Optional . Object as the callback to execute , Pass to function , Used as a "this
" Value .
So this problem can be explained as
[
parseInt('1',0),
parseInt('2',1),
parseInt('3',2)
]
Look again parseInt() Definition of function
grammar
parseInt(string, radix);
parseInt(string, radix) Parses a string and returns a decimal integer with the specified cardinality ,radix
yes 2-36 Integer between , Represents the cardinality of the parsed string .
Parameters
string
The value to be parsed . If the parameter is not a string , Then convert it to a string ( Use ToString
Abstract operations ). Whitespace at the beginning of the string will be ignored .
radix
Optional
from 2
To 36
, Represents the cardinality of the string . For example, specify 16
Indicates that the parsed value is a hexadecimal number . Please note that ,10 Not the default ! The description later in the article explains when the parameter radix
The specific behavior of this function when it is not transmitted .
Return value
An integer parsed from a given string .
perhaps NaN, When
radix
Less than2
Or greater than36
, or- The first non space character cannot be converted to a number .
If radix
yes undefined
、0
Or unspecified ,JavaScript It is assumed that :
- If you enter
string
With0x
or0X
( One 0, Followed by lowercase or uppercase X) start , that radix Assumed to be 16, The rest of the string is parsed as a hexadecimal number . - If you enter
string
With "0
"(0) start ,radix
Assumed to be8
( octal ) or10
( Decimal system ). Which one to choose radix It depends on the realization of .ECMAScript 5 Clarified that... Should be used 10 ( Decimal system ), But not all browsers support . therefore , In the use ofparseInt
when , Be sure to specify a radix. - If you enter
string
Start with any other value ,radix
yes10
( Decimal system ).
If the first character cannot be converted to a number ,parseInt
Returns the NaN
.
The answer for :
[1, NaN, NaN]
边栏推荐
- Virtual machine installation deepin system
- Why can't you remember when reading? Why can't you remember- My technology learning methodology
- One click generation and conversion of markdown directory to word format
- 解决:代理抛出异常错误
- Leetcode merge sort linked list
- Detailed process of DC-1 range construction and penetration practice (DC range Series)
- 初学爬虫-笔趣阁爬虫
- Pytest learning ----- pytest assertion of interface automation testing
- idea自动导包和自动删包设置
- Let genuine SMS pressure measurement open source code
猜你喜欢
DC-1靶场搭建及渗透实战详细过程(DC靶场系列)
Realize the function of data uploading
How to modify data file path in DM database
数学知识(欧拉函数)
农业生态领域智能机器人的应用
Keil compilation code of CY7C68013A
Deep understanding of lambda expressions
Practical problem solving ability of steam Education
Steam教育的实际问题解决能力
Leetcode- insert and sort the linked list
随机推荐
My first experience of shadowless cloud computer
Markdown编辑语法
Rhcsa --- work on the third day
6.30 year end summary, end of student age
06 装饰(Decorator)模式
6.30年终小结,学生时代结束
Analyzing the hands-on building tutorial in children's programming
CorelDRAW graphics suite2022 free graphic design software
I sorted out some basic questions about opencv AI kit.
Let正版短信测压开源源码
農業生態領域智能機器人的應用
Lm09 Fisher inverse transform inversion mesh strategy
MySQL table insert Chinese change? Solution to the problem of No
Deeply understand the concepts of synchronization and asynchrony, blocking and non blocking, parallel and serial
Hcip day 17
LeetCode-对链表进行插入排序
Flag bits in assembly language: CF, PF, AF, ZF, SF, TF, if, DF, of
Oracle stored procedure and job task setting
面试会问的 Promise.all()
Steam教育的实际问题解决能力