当前位置:网站首页>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]边栏推荐
- Virtual machine installation deepin system
- How to write a client-side technical solution
- Arbre binaire pour résoudre le problème (2)
- Unity particle Foundation
- LM09丨费雪逆变换反转网格策略
- Steam教育的实际问题解决能力
- Orthogonal test method and function diagram method for test case design
- Hcip day 17
- Go GC garbage collection notes (three color mark)
- Comp 250 parsing
猜你喜欢

Go Chan's underlying principles

Deeply understand the concepts of synchronization and asynchrony, blocking and non blocking, parallel and serial

Thinkphp内核工单系统源码商业开源版 多用户+多客服+短信+邮件通知

Summary of common string processing functions in C language

Application of intelligent robot in agricultural ecology

Orthogonal test method and function diagram method for test case design

The core idea of performance optimization, dry goods sharing

Cultivate primary and secondary school students' love for educational robots

VMware installation win10 reports an error: operating system not found

Embedded-c language-9-makefile/ structure / Consortium
随机推荐
Cultivate primary and secondary school students' love for educational robots
二叉树解题(一)
06 decorator mode
Lay the foundation for children's programming to become a basic discipline
10 minute quick start UI automation ----- puppeter
geotrust ov多域名ssl證書一年兩千一百元包含幾個域名?
The solution to the complexity brought by lambda expression
Ognl和EL表达式以及内存马的安全研究
6月书讯 | 9本新书上市,阵容强大,闭眼入!
Solution of DM database unable to open graphical interface
What data does the main account of Zhengda Meiou 4 pay attention to?
Mapping location after kotlin confusion
AcrelEMS高速公路微电网能效管理平台与智能照明解决方案智慧点亮隧道
Record the bug of unity 2020.3.31f1 once
数学知识——快速幂的理解及例题
The core idea of performance optimization, dry goods sharing
农业生态领域智能机器人的应用
解析少儿编程中的动手搭建教程
Comp 250 parsing
idea自動導包和自動删包設置