码迷,mamicode.com
首页 > 编程语言 > 详细

[Javascript] Use Number() to convert to Number if possilbe

时间:2016-07-19 20:27:54      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

Use map() and Number() to convert to number if possilbe or NaN.

 

var str = ["1","1.23","3","4.0","five", undefined, .00];
var num = str.map( (s) => {
  return Number(s);
});

console.log(num); //[1, 1.23, 3, 4, NaN, NaN, 0]

 

[Javascript] Use Number() to convert to Number if possilbe

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/5685827.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!