text: (window.webpackJsonp=window.webpackJsonp||[]).push([[59],{450:function(t,a,s){"use strict";s.r(a);var n=s(27),r=Object(n.a)({},(function(){var t=this,a=t.$createElement,s=t._self._c||a;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"_1-2-3-map-parseint-的输出结果？"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-2-3-map-parseint-的输出结果？"}},[t._v("#")]),t._v(' ["1","2","3"].map(parseInt)的输出结果？')]),t._v(" "),s("h2",{attrs:{id:"parseint-string-radix"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#parseint-string-radix"}},[t._v("#")]),t._v(" parseInt(string,radix)")]),t._v(" "),s("p",[t._v("将一个字符串"),s("code",[t._v("string")]),t._v("转换成"),s("strong",[t._v("10进制数")]),t._v("，"),s("code",[t._v("string")]),t._v("基数为"),s("code",[t._v("radix")]),t._v("。等同于"),s("code",[t._v("Number.parseInt()")]),t._v("。")]),t._v(" "),s("p",[s("strong",[t._v("永远都要明确给出"),s("code",[t._v("radix")]),t._v("参数的值")]),t._v("。如果遇到没给定的情况，默认为10，若"),s("code",[t._v("string")]),t._v("以"),s("code",[t._v("0x或0X")]),t._v("开头，为16。")]),t._v(" "),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("提示")]),t._v(" "),s("p",[t._v("直白的说，该方法就是先将"),s("code",[t._v("string")]),t._v("转换为"),s("code",[t._v("radix")]),t._v("进制数，然后转换成10进制数。")])]),t._v(" "),s("h2",{attrs:{id:"parsefloat-string"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#parsefloat-string"}},[t._v("#")]),t._v(" parseFloat(string)")]),t._v(" "),s("p",[t._v("将一个字符串"),s("code",[t._v("string")]),t._v("解析成浮点数。等同于"),s("code",[t._v("Number.parseFloat()")]),t._v("。")]),t._v(" "),s("h2",{attrs:{id:"解题："}},[s("a",{staticClass:"header-anchor",attrs:{href:"#解题："}},[t._v("#")]),t._v(" 解题：")]),t._v(" "),s("p",[s("strong",[t._v("两个API解释：")])]),t._v(" "),s("ul",[s("li",[s("strong",[t._v("parseInt(string,radix)")]),t._v(":\n"),s("ul",[s("li",[t._v("将"),s("code",[t._v("string")]),t._v("视为"),s("code",[t._v("radix")]),t._v("进制的数字，转换成十进制，并返回")]),t._v(" "),s("li",[s("code",[t._v("radix")]),t._v("不传或者传0时，等价传10")]),t._v(" "),s("li",[s("code",[t._v("radix")]),t._v("传"),s("code",[t._v("0X")]),t._v("时，等价传16")]),t._v(" "),s("li",[s("code",[t._v("radix")]),t._v("传"),s("code",[t._v("1")]),t._v("或者大于"),s("code",[t._v("36")]),t._v("时，函数返回"),s("code",[t._v("NaN")])])])]),t._v(" "),s("li",[s("strong",[t._v("map(callback(item,index,arr),thisarg)")]),t._v(":\n"),s("ul",[s("li",[t._v("map接受两个参数，callback函数以及callback函数内部的this指向")])])])]),t._v(" "),s("br"),t._v(" "),s("p",[t._v("弄懂了上面这两个API，该题目可以改写成如下格式：")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"1"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"2"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"3"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("map")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("item"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("index")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n  "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("parseInt")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("item"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("index"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),s("p",[t._v("相当于处理：")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("parseInt")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"1"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// radix传0时，相当于传10，所以返回值为 1")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("parseInt")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"2"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// radix传1或大于36时，直接返回       NaN")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("parseInt")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"3"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v('// radix常规值是2-36，"3"不可能是二进制，所以返回NaN')]),t._v("\n")])])]),s("p",[t._v("所以最终的结果是：[1,NaN,NaN]")])])}),[],!1,null,null,null);a.default=r.exports}}]);