The _.isTypedArray() method is used to find whether the given value is a typed array or not. It returns True if the given value is a typed array. Otherwise, it returns false.
Syntax:
_.isTypedArray(value)
Parameters: This method accepts a single parameter as mentioned above and described below:
-
value: This parameter holds the value to check.
Return Value: This method returns true if value is a typed array, else false.
Note: Here, const _ = require(‘lodash’) is used to import the lodash library into the file.
Example 1:
// Requiring the lodash library const _ = require( "lodash" ); // Use of _.isTypedArray() method // Passing a array as an argument console.log(_.isTypedArray([])); // Passing an array with value as an argument console.log(_.isTypedArray([1, 2, 3, 4])); |
Output:
false false
Example 2:
// Requiring the lodash library const _ = require( "lodash" ); // Use of _.isTypedArray() method // Passing a typedArray objects Int8Array console.log(_.isTypedArray( new Int8Array(8))); // Passing a typedArray objects Float64Array console.log(_.isTypedArray( new Float64Array())); |
Output:
true true
Note: This will not work in normal JavaScript because it requires the library lodash to be installed.
Reference: https://lodash.com/docs/4.17.15#isTypedArray