javascript 和测试数字

标签 javascript

Possible Duplicate:
Is there a (built-in) way in JavaScript to check if a string is a valid number?

我在 riak map 缩减作业中使用 JS。我有一个想要映射的号码,并且需要是一个号码。

如果我有一个变量:

 var wp=sfggz5341&& or var=100

如何测试 if 数字?

例如

if wp==Number:    
    OK 
else:    
    pass

最佳答案

您可以使用 typeof 运算符(有关详细信息,请参阅 MDN):

var wp = "sfggz53141";
if (typeof wp === "number") {
    // number here
} else if (typeof wp === "string") {
    // string here
}

关于javascript 和测试数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14495426/

相关文章:

javascript - AngularJS 创建虚拟指令

javascript - 浏览器 javascript 可以监听路由/url 吗?

javascript - 只选择所有小写字符的单词javascript

javascript - 为什么 Youtube iFrame API 检测不到状态变化

javascript - VueJS 在 v-for 中仅选择一个元素

javascript - ExtJS 列表数据 View

javascript - 传承值(value)

javascript - Jest/Enzyme 图像加载回调未运行

javascript - 将 FF 扩展移植到 IE : no global window object in JS WSC

javascript - 重构庞大的 JavaScript 项目