Data Type

Return the data type of an array.

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 );
}