0.3.0 • Published 4 months ago
@stdlib/array-dtype v0.3.0
Data Type
Return the data type of an array.
Installation
npm install @stdlib/array-dtype
Usage
var dtype = require( '@stdlib/array-dtype' );
dtype( array )
Returns the data type of an array
.
var Float64Array = require( '@stdlib/array-float64' );
var arr = new Float64Array( 10 );
var dt = dtype( arr );
// returns 'float64'
If provided an argument having an unknown or unsupported data type, the function returns null
.
var dt = dtype( 'beep' );
// returns null
Examples
var dtypes = require( '@stdlib/array-dtypes' );
var ctors = require( '@stdlib/array-ctors' );
var dtype = require( '@stdlib/array-dtype' );
var DTYPES;
var ctor;
var arr;
var len;
var dt;
var i;
// Get a list of supported array data types:
DTYPES = dtypes();
// Array length:
len = 10;
// For each supported data type, create an array and confirm its data type...
for ( i = 0; i < DTYPES.length; i++ ) {
ctor = ctors( DTYPES[ i ] );
arr = new ctor( len );
dt = dtype( arr );
console.log( '%s == %s => %s', DTYPES[ i ], dt, DTYPES[ i ] === dt );
}
See Also
@stdlib/array-dtypes
: list of array data types.
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.