- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Node.js – util.types.isArrayBufferView() Method
The util.types.isArrayBufferView() checks whether the passed value is an instance of the ArrayBuffer views, or typed array objects like DataView. This method returns True if the above conditions are satisfied, else it returns False.
Syntax
util.types.isArrayBufferView(value)
Parameters
It takes only one parameter −
value − This input parameter takes input for the required datatype and checks if it is an ArrayBuffer or a typed array object
It returns True or False based upon the input value passed.
Example 1
Create a file with the name "isArrayBufferView.js" and copy the following code snippet. After creating the file, use the command "node isArrayBufferView.js" to run this code.
// util.types.isArrayBufferView() Demo Example // Importing the util module const util = require('util'); // Defining only types module from util const {types} = require('util'); // Passing ArrayBuffer as input parameter console.log("1. ", util.types.isArrayBufferView(new ArrayBuffer())); // Passing the buffer parameter with value console.log("2. ", util.types.isArrayBufferView(Buffer.from('tutorials point'))); // Passing a Float64Array console.log("3. ", util.types.isArrayBufferView(new Float64Array())); // Passing SharedArrayBuffer as input parameter console.log("4. ", util.types.isArrayBufferView(new SharedArrayBuffer()));
Output
C:\home
ode>> node isArrayBufferView.js 1. false 2. true 3. true 4. false
Example 2
// util.types.isArrayBufferView() Demo Example // Importing the util module const util = require('util'); // Defining only types module from util const {types} = require('util'); // Defining some common buffers // Create a 16byte buffer var buffer = new ArrayBuffer(16); // Create a DataView referring to the buffer var buffer1 = new DataView(buffer); // Create a Int8Array view referring to the buffer var buffer2 = new Int8Array(buffer); // Put value of 32bits buffer1.setInt32(0, 0x76543210); // Passing ArrayBuffer as input parameter console.log("1. ", util.types.isArrayBufferView(buffer)); // Passing the buffer parameter with value console.log("2. ", util.types.isArrayBufferView(buffer1)); // Passing a Float64Array console.log("3. ", util.types.isArrayBufferView(new Float64Array())); // Passing SharedArrayBuffer as input parameter console.log("4. ", util.types.isArrayBufferView(buffer2));
Output
C:\home
ode>> node isArrayBufferView.js 1. false 2. true 3. true 4. true
Advertisements