Node.js util.types.isInt16Array() 方法
util.types.isInt16Array() 方法是 util 模块的内置应用程序编程接口,用于检查 node.js 中 Int16Array 的类型。
句法:
util.types.isInt16Array( value )
参数:此方法接受上面提到的和下面描述的单个参数。
- value:它是保存任何数据类型的必需参数。
返回值:它返回一个布尔值,如果该值是一个 Int16Array 对象,则返回 TRUE,否则返回 FALSE。
以下示例说明了 Node.js 中 util.types.isInt16Array() 方法的使用:
示例 1:
// Node.js program to demonstrate the
// util.types.isInt16Array() Method
// Allocating util module
const util = require('util');
// Value to be passed as parameter of
// util.types.isInt16Array() method
var v1 = new BigInt64Array();
var v2 = new BigUint64Array();
var v3 = new Float32Array();
var v4 = new Int8Array();
var v5 = new Int16Array();
// Printing the returned value from
// util.types.isInt16Array() method
console.log(util.types.isInt16Array(v1));
console.log(util.types.isInt16Array(v2));
console.log(util.types.isInt16Array(v3));
console.log(util.types.isInt16Array(v4));
console.log(util.types.isInt16Array(v5));
输出:
false
false
false
false
true
示例 2:
// Node.js program to demonstrate the
// util.types.isInt16Array() Method
// Allocating util module
const util = require('util');
// Value to be passed as parameter of
// util.types.isInt16Array() method
var v1 = new Int8Array();
var v2 = new Int16Array();
// Calling util.types.isInt16Array() method
if (util.types.isInt16Array(v1))
console.log("The passed value is a Int16Array.");
else
console.log("The passed value is not a Int16Array");
if (util.types.isInt16Array(v2))
console.log("The passed value is a Int16Array.");
else
console.log("The passed value is not a Int16Array");
输出:
The passed value is not a Int16Array.
The passed value is a Int16Array
注意:上面的程序将使用node filename.js
命令编译和运行。
参考: https://nodejs.org/api/util.html#util_util_types_isint16array_value