Arrays.
var ns = require( '@stdlib/array' );
Arrays.
var o = ns;
// returns {...}
The namespace exports the following array constructors:
ArrayBuffer( size )
: Returns anArrayBuffer
having a specified number of bytes.Float32Array()
: A typed array constructor which returns a typed array representing an array of single-precision floating-point numbers in the platform byte order.Float32Array( length )
: Returns a typed array having a specified length.Float32Array( typedarray )
: Creates a typed array from another typed array.Float32Array( obj )
: Creates a typed array from an array-likeobject
or iterable.Float32Array( buffer[, byteOffset[, length]] )
: Returns a typed array view of anArrayBuffer
.Float64Array()
: A typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in the platform byte order.Float64Array( length )
: Returns a typed array having a specified length.Float64Array( typedarray )
: Creates a typed array from another typed array.Float64Array( obj )
: Creates a typed array from an array-likeobject
or iterable.Float64Array( buffer[, byteOffset[, length]] )
: Returns a typed array view of anArrayBuffer
.Int16Array()
: A typed array constructor which returns a typed array representing an array of twos-complement 16-bit signed integers in the platform byte order.Int16Array( length )
: Returns a typed array having a specified length.Int16Array( typedarray )
: Creates a typed array from another typed array.Int16Array( obj )
: Creates a typed array from an array-likeobject
or iterable.Int16Array( buffer[, byteOffset[, length]] )
: Returns a typed array view of anArrayBuffer
.Int32Array()
: A typed array constructor which returns a typed array representing an array of twos-complement 32-bit signed integers in the platform byte order.Int32Array( length )
: Returns a typed array having a specified length.Int32Array( typedarray )
: Creates a typed array from another typed array.Int32Array( obj )
: Creates a typed array from an array-likeobject
or iterable.Int32Array( buffer[, byteOffset[, length]] )
: Returns a typed array view of anArrayBuffer
.Int8Array()
: A typed array constructor which returns a typed array representing an array of twos-complement 8-bit signed integers in the platform byte order.Int8Array( length )
: Returns a typed array having a specified length.Int8Array( typedarray )
: Creates a typed array from another typed array.Int8Array( obj )
: Creates a typed array from an array-likeobject
or iterable.Int8Array( buffer[, byteOffset[, length]] )
: Returns a typed array view of anArrayBuffer
.SharedArrayBuffer( size )
: Returns aSharedArrayBuffer
having a specified number of bytes.Uint16Array()
: A typed array constructor which returns a typed array representing an array of 16-bit unsigned integers in the platform byte order.Uint16Array( length )
: Returns a typed array having a specified length.Uint16Array( typedarray )
: Creates a typed array from another typed array.Uint16Array( obj )
: Creates a typed array from an array-likeobject
or iterable.Uint16Array( buffer[, byteOffset[, length]] )
: Returns a typed array view of anArrayBuffer
.Uint32Array()
: A typed array constructor which returns a typed array representing an array of 32-bit unsigned integers in the platform byte order.Uint32Array( length )
: Returns a typed array having a specified length.Uint32Array( typedarray )
: Creates a typed array from another typed array.Uint32Array( obj )
: Creates a typed array from an array-likeobject
or iterable.Uint32Array( buffer[, byteOffset[, length]] )
: Returns a typed array view of anArrayBuffer
.Uint8Array()
: A typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order.Uint8Array( length )
: Returns a typed array having a specified length.Uint8Array( typedarray )
: Creates a typed array from another typed array.Uint8Array( obj )
: Creates a typed array from an array-likeobject
or iterable.Uint8Array( buffer[, byteOffset[, length]] )
: Returns a typed array view of anArrayBuffer
.Uint8ClampedArray()
: A typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order clamped to0-255
.Uint8ClampedArray( length )
: Returns a typed array having a specified length.Uint8ClampedArray( typedarray )
: Creates a typed array from another typed array.Uint8ClampedArray( obj )
: Creates a typed array from an array-likeobject
or iterable.Uint8ClampedArray( buffer[, byteOffset[, length]] )
: Returns a typed array view of anArrayBuffer
.
var arr = new ns.Int32Array( 5 );
// returns <Int32Array>[ 0, 0, 0, 0, 0 ]
Alternatively, use the typedarray
function to create a typed array of a given data type:
typedarray( [dtype] )
: Creates a typed array having a specified data typedtype
.typedarray( length[, dtype] )
: Returns a typed array having a specifiedlength
.typedarray( typedarray[, dtype] )
: Creates a typed array from another typed array.typedarray( obj[, dtype] )
: Creates a typed array from an array-likeobject
or iterable.typedarray( buffer[, byteOffset[, length]][, dtype] )
: Returns a typed array view of anArrayBuffer
.
var arr1 = ns.typedarray( 5 );
// returns <Float64Array>[ 0.0, 0.0, 0.0, 0.0, 0.0 ]
var arr2 = ns.typedarray( 5, 'uint8' );
// returns <Uint8Array>[ 0, 0, 0, 0, 0 ]
You can use the following functions to retrieve a list of available data types:
arrayDataTypes()
: Returns a list of array data types.typedarrayDataTypes()
: Returns a list of typed array data types.
var DTYPES = ns.arrayDataTypes();
// returns [ 'float32', 'float64', 'generic', 'int16', 'int32', 'int8', 'uint16', 'uint32', 'uint8', 'uint8c' ]
Furthermore, the namespace contains utility functions to retrieve a given constructor:
arrayCtors( dtype )
: Returns an array constructor for a specified data type.typedarrayCtors( dtype )
: Returns a typed array constructor for a specified data type.
var ctor = ns.typedarrayCtors( 'float64' );
// returns <Function>
ctor = ns.typedarrayCtors( 'int' );
// returns null
Lastly, the namespace contains various other functions for dealing with arrays, including functions to convert arrays from one data type to another or to serialize them as JSON and vice versa.
convertArray( arr, dtype )
: Converts anarray
to an array of a different data type.convertArraySame( x, y )
: Converts anarray
to the same data type as a second inputarray
.arrayDataType( array )
: Returns the data type of anarray
.reviveTypedArray( key, value )
: Revives a JSON-serialized typed array.typedarray2json( typedarray )
: Returns a JSON representation of a typed array.
var getKeys = require( '@stdlib/utils/keys' );
var ns = require( '@stdlib/array' );
console.log( getKeys( ns ) );