📜  Node.js util.types.isInt8Array() 方法

📅  最后修改于: 2022-05-13 01:56:48.739000             🧑  作者: Mango

Node.js util.types.isInt8Array() 方法

util.types.isInt8Array() 方法是 util 模块的内置应用程序编程接口,用于在 node.js 中对 Int8Array 进行类型检查。

句法:

util.types.isInt8Array( value )

参数:此方法接受上面提到的和下面描述的单个参数。

  • value:它是保存任何数据类型的必需参数。

返回值:它返回一个布尔值,如果该值是一个 Int8Array 对象,则返回 TRUE,否则返回 FALSE。

以下示例说明了 Node.js 中 util.types.isInt8Array() 方法的使用:

示例 1:

// Node.js program to demonstrate the   
// util.types.isInt8Array() Method 
  
// Allocating util module
const util = require('util');
  
// Value to be passed as parameter of
// util.types.isInt8Array() method
var v1 = new BigInt64Array();
var v2 = new BigUint64Array();
var v3 = new Float32Array();
var v4 = new ArrayBuffer();
var v5 = new Int8Array();
  
// Printing the returned value from
// util.types.isInt8Array() method
console.log(util.types.isInt8Array(v1));
console.log(util.types.isInt8Array(v2));
console.log(util.types.isInt8Array(v3));
console.log(util.types.isInt8Array(v4));
console.log(util.types.isInt8Array(v5));

输出:

false
false
false
false
true

示例 2:

// Node.js program to demonstrate the   
// util.types.isInt8Array() Method 
  
// Allocating util module
const util = require('util');
  
// Value to be passed as parameter of
// util.types.isInt8Array() method
var v1=new Int8Array();
var v2=new Int16Array();
   
// Calling util.types.isInt8Array() method
if(util.types.isInt8Array(v1))
    console.log("The passed value is a Int8Array.");
else
    console.log("The passed value is not a Int8Array");
   
if(util.types.isInt8Array(v2))
    console.log("The passed value is a Int8Array.");
else
    console.log("The passed value is not a Int8Array");

输出:

The passed value is a Int8Array.
The passed value is not a Int8Array

注意:上面的程序将使用node filename.js命令编译和运行。

参考: https://nodejs.org/api/util.html#util_util_types_isint8array_value