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

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

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

util 模块的util.types.isInt32Array() 方法主要是为了支持 Node.js 自己的内部 API 的需求而设计的。用于检查方法中传入的实例是否为内置的 Int32Array 实例。

句法:

util.types.isInt32Array( value )

参数:此方法接受一个包含任何值的单个参数,即任何模块的实例。

返回值:此方法返回一个布尔值,即如果传递的值是 Int32Array 的实例,则返回 true,否则返回false

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

示例 1:

// Node.js program to demonstrate the   
// util.types.isInt32Array() method
  
// It includes util module
const util = require('util');
  
// Return false as passed instance is of map
console.log(util.types.isInt32Array(new Map()));
  
// Return true as passed instance is of Int32Array
console.log(util.types.isInt32Array(new Int32Array()));

输出:

false
true

示例 2:

// Node.js program to demonstrate the   
// util.types.isInt32Array() method
  
// It includes util module
const util = require('util');
  
// Making an instance of Int32Array
// of size 2
var array1 = new Int32Array(2);
  
// Initializing the zeroth element 
array1[0] = 42;
  
// Returns true as passed instance is of Int32Array
console.log(util.types.isInt32Array(array1));
   
// Making an instance of Int32Array
var array2 = new Int32Array([21, 31]);
  
// Returns true as passed instance is of Int32Array
console.log(util.types.isInt32Array(array2));
  
// Making an instance of Int32Array
var array3 = new Int32Array([21, 31]);
  
// Making another instance of Int32Array by
// passing an instance of Int32Array
var array4 = new Int32Array(array3);
  
// Returns true as passed instance is of Int32Array
console.log(util.types.isInt32Array(array4));
  
// Making an instance of Int16Array of size 2
var array5 = new Int16Array(2);
  
// Initializing the zeroth element 
array5[0] = 10;
  
// Returns false as passed instance is of Int16Array
console.log(util.types.isInt32Array(array5));

输出:

true
true
true
false

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