当前位置:网站首页>js面试收藏试题1
js面试收藏试题1
2022-07-02 04:48:00 【幻彩希】
//求输出结果
console.log(['1','2','3'].map(parseInt))JavaScript map()函数使用
一、概念
map()方法定义在JavaScript的Array中,它返回一个新的数组,数组中的元素为原始数组调用函数处理后的值。
注意:
map()不会对空数组进行检测map()不会改变原始数组
二、参数说明:
array.map(function(currentValue, index, arr), thisIndex)
function(currentValue, index, arr):必须。为一个函数,数组中的每个元素都会执行这个函数。其中函数参数:
currentValue:必须。当前元素的的值。index:可选。当前元素的索引。arr:可选。当前元素属于的数组对象。
thisValue:可选。对象作为该执行回调时使用,传递给函数,用作"this"的值。
所以这道题可以解释为
[
parseInt('1',0),
parseInt('2',1),
parseInt('3',2)
]再看parseInt()函数的定义
语法
parseInt(string, radix);
parseInt(string, radix) 解析一个字符串并返回指定基数的十进制整数,radix 是 2-36 之间的整数,表示被解析字符串的基数。
参数
string
要被解析的值。如果参数不是一个字符串,则将其转换为字符串 (使用 ToString抽象操作)。字符串开头的空白符将会被忽略。
radix 可选
从 2 到 36,表示字符串的基数。例如指定 16 表示被解析值是十六进制数。请注意,10 不是默认值!文章后面的描述解释了当参数 radix 不传时该函数的具体行为。
返回值
从给定的字符串中解析出的一个整数。
或者 NaN,当
radix小于2或大于36,或- 第一个非空格字符不能转换为数字。
如果 radix 是 undefined、0 或未指定的,JavaScript 会假定以下情况:
- 如果输入的
string以0x或0X(一个 0,后面是小写或大写的 X)开头,那么 radix 被假定为 16,字符串的其余部分被当做十六进制数去解析。 - 如果输入的
string以 "0"(0)开头,radix被假定为8(八进制)或10(十进制)。具体选择哪一个 radix 取决于实现。ECMAScript 5 澄清了应该使用 10 (十进制),但不是所有的浏览器都支持。因此,在使用parseInt时,一定要指定一个 radix。 - 如果输入的
string以任何其他值开头,radix是10(十进制)。
如果第一个字符不能转换为数字,parseInt 会返回 NaN。
答案为:
[1, NaN, NaN]边栏推荐
- Analyze the space occupied by the table according to segments, clusters and pages
- DJB Hash
- Markdown编辑语法
- Change deepin to Alibaba image source
- Steam教育的实际问题解决能力
- LeetCode-对链表进行插入排序
- 10 minute quick start UI automation ----- puppeter
- There is no prompt for SQL in idea XML, and the dialect setting is useless.
- Common errors of dmrman offline backup
- Unit testing classic three questions: what, why, and how?
猜你喜欢

LeetCode-归并排序链表

Cannot activate CONDA virtual environment in vscode

idea自動導包和自動删包設置

List of common bugs in software testing

Win10 disk management compressed volume cannot be started

One click generation and conversion of markdown directory to word format

How to recover deleted data in disk

万卷共知,一书一页总关情,TVP读书会带你突围阅读迷障!

Social media search engine optimization and its importance

Three years of experience in Android development interview (I regret that I didn't get n+1, Android bottom development tutorial
随机推荐
Introduction to Luogu 3 [circular structure] problem list solution
Markdown编辑语法
There is no prompt for SQL in idea XML, and the dialect setting is useless.
Orthogonal test method and function diagram method for test case design
Binary tree problem solving (1)
win11安装pytorch-gpu遇到的坑
DC-1靶场搭建及渗透实战详细过程(DC靶场系列)
6.30年终小结,学生时代结束
Mysql表insert中文变?号的问题解决办法
[improvement class] st table to solve the interval maximum value problem [2]
【毕业季·进击的技术er】年少有梦,何惧彷徨
Pytoch --- use pytoch to realize u-net semantic segmentation
Summary of main account information of zhengdaliu 4
Ognl和EL表达式以及内存马的安全研究
解析少儿编程中的动手搭建教程
Exposure X8标准版图片后期滤镜PS、LR等软件的插件
Vmware安装win10报错:operating system not found
One step implementation of yolox helmet detection (combined with oak intelligent depth camera)
Idea autoguide package and autodelete package Settings
Design and implementation of general interface open platform - (44) log processing of API services