当前位置:网站首页>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 OfArrayin , 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
radixLess than2Or 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
stringWith0xor0X( 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
stringWith "0"(0) start ,radixAssumed 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 ofparseIntwhen , Be sure to specify a radix. - If you enter
stringStart with any other value ,radixyes10( Decimal system ).
If the first character cannot be converted to a number ,parseInt Returns the NaN.
The answer for :
[1, NaN, NaN]边栏推荐
- 关于Steam 教育的知识整理
- MySQL table insert Chinese change? Solution to the problem of No
- 二叉树解题(二)
- How to recover deleted data in disk
- Interview question: do you know the difference between deep copy and shallow copy? What is a reference copy?
- Application of intelligent robot in agricultural ecology
- Several methods of capturing packets under CS framework
- Pit encountered in win11 pytorch GPU installation
- The solution to the complexity brought by lambda expression
- Unit testing classic three questions: what, why, and how?
猜你喜欢

Idea autoguide package and autodelete package Settings

数学问题(数论)试除法做质数的判断、分解质因数,筛质数

The underlying principle of go map (storage and capacity expansion)

Detailed process of DC-1 range construction and penetration practice (DC range Series)

Future trend of automated testing ----- self healing technology

Steam教育的实际问题解决能力

解析少儿编程中的动手搭建教程

Summary of main account information of zhengdaliu 4

Application d'un robot intelligent dans le domaine de l'agroécologie

Several methods of capturing packets under CS framework
随机推荐
农业生态领域智能机器人的应用
Lay the foundation for children's programming to become a basic discipline
農業生態領域智能機器人的應用
Use of typescript classes
06 装饰(Decorator)模式
What are the rules and trading hours of agricultural futures contracts? How much is the handling fee deposit?
Social media search engine optimization and its importance
正大美欧4的主账户关注什么数据?
Cache consistency solution - how to ensure the consistency between the cache and the data in the database when changing data
Hcip day 17
6月书讯 | 9本新书上市,阵容强大,闭眼入!
Use of Baidu map
Rhcsa --- work on the third day
Common errors of dmrman offline backup
Knowledge arrangement about steam Education
Deep understanding of lambda expressions
Detailed process of DC-1 range construction and penetration practice (DC range Series)
Acelems Expressway microgrid energy efficiency management platform and intelligent lighting solution intelligent lighting tunnel
培养中小学生对教育机器人的热爱之心
Go GC garbage collection notes (three color mark)