_。isInteger()方法检查给定值是否为Integer值,然后返回对应的布尔值。
用法:
_.isInteger( value );
参数:
- value:给定值以检查整数值。
返回值:此方法返回一个布尔值(如果给定值为Integer,则返回true,否则返回false)。
注意:由于它需要安装underscore.js contrib库,因此在正常的JavaScript中将无法使用。 Underscore.js contrib库可以使用安装npm安装underscore-contrib。
范例1:
Java脚本
// Defining underscore contrib variable
var _ = require('underscore-contrib');
// Checking
console.log("The Value is Integer:"
+ _.isInteger(-4));
输出:
The Value is Integer:true
范例2:
Java脚本
// Defining underscore contrib variable
var _ = require('underscore-contrib');
// Checking
console.log("The Value is Integer:"
+ _.isInteger(4.2));
输出:
The Value is Integer:false
范例3:对于此方法,值4.0和4都将被视为整数,因此此方法将返回true。
Java脚本
// Defining underscore contrib variable
var _ = require('underscore-contrib');
// Checking
console.log("The Value is Integer:"
+ _.isInteger(4.0));
输出:
The Value is Integer:true
范例4:包含Integer值的字符串将返回true。
Java脚本
// Defining underscore contrib variable
var _ = require('underscore-contrib');
// Checking
console.log("The Value is Integer:"
+ _.isInteger("4"));
输出:
The Value is Integer:true
相关用法
- Javascript Number.isInteger( )用法及代码示例
- Lodash _.last()用法及代码示例
- JQuery die()用法及代码示例
- p5.js Table get()用法及代码示例
- HTML DOM contains()用法及代码示例
- JQuery add()用法及代码示例
- HTML DOM after()用法及代码示例
- HTML DOM before()用法及代码示例
- p5.js Table set()用法及代码示例
- JQuery css()用法及代码示例
- JQuery off()用法及代码示例
- JQuery get()用法及代码示例
- Collect.js all()用法及代码示例
- JQuery is()用法及代码示例
- JQuery before()用法及代码示例
- underscore.js _.nth()用法及代码示例
注:本文由纯净天空筛选整理自taran910大神的英文原创作品 Underscore.js _.isInteger() Method。非经特殊声明,原始代码版权归原作者所有,本译文的传播和使用请遵循“署名-相同方式共享 4.0 国际 (CC BY-SA 4.0)”协议。