# Arrays

[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] [![dependencies][dependencies-image]][dependencies-url]

> Arrays.

## Installation

```bash
npm install @stdlib/array
```


## Usage

```javascript
var ns = require( '@stdlib/array' );
```

#### ns

Arrays.

```javascript
var o = ns;
// returns {...}
```

The namespace exports the following array constructors:

-   [`ArrayBuffer( size )`][@stdlib/array/buffer]: constructor which returns an object used to represent a generic, fixed-length raw binary data buffer.
-   [`Float32Array()`][@stdlib/array/float32]: typed array constructor which returns a typed array representing an array of single-precision floating-point numbers in the platform byte order.
-   [`Float64Array()`][@stdlib/array/float64]: typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in the platform byte order.
-   [`Int16Array()`][@stdlib/array/int16]: typed array constructor which returns a typed array representing an array of twos-complement 16-bit signed integers in the platform byte order.
-   [`Int32Array()`][@stdlib/array/int32]: typed array constructor which returns a typed array representing an array of twos-complement 32-bit signed integers in the platform byte order.
-   [`Int8Array()`][@stdlib/array/int8]: typed array constructor which returns a typed array representing an array of twos-complement 8-bit signed integers in the platform byte order.
-   [`SharedArrayBuffer( size )`][@stdlib/array/shared-buffer]: constructor returning an object used to represent a generic, fixed-length raw binary data buffer which can be used to create views of shared memory.
-   [`Uint16Array()`][@stdlib/array/uint16]: typed array constructor which returns a typed array representing an array of 16-bit unsigned integers in the platform byte order.
-   [`Uint32Array()`][@stdlib/array/uint32]: typed array constructor which returns a typed array representing an array of 32-bit unsigned integers in the platform byte order.
-   [`Uint8Array()`][@stdlib/array/uint8]: typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order.
-   [`Uint8ClampedArray()`][@stdlib/array/uint8c]: typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order clamped to 0-255.

```javascript
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()`][@stdlib/array/typed]: create a typed array.

```javascript
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 ]
```

The namespace contains functions to create arrays pre-filled with spaced values:

-   [`datespace( start, stop[, length][, opts] )`][@stdlib/array/datespace]: generate an array of linearly spaced dates.
-   [`incrspace( start, stop[, increment] )`][@stdlib/array/incrspace]: generate a linearly spaced numeric array using a provided increment.
-   [`linspace( start, stop[, length] )`][@stdlib/array/linspace]: generate a linearly spaced numeric array.
-   [`logspace( a, b[, length] )`][@stdlib/array/logspace]: generate a logarithmically spaced numeric array.

You can use the following functions to retrieve a list of available data types:

-   [`arrayDataTypes()`][@stdlib/array/dtypes]: list of array data types.
-   [`typedarrayComplexDataTypes()`][@stdlib/array/typed-complex-dtypes]: list of complex typed array data types.
-   [`typedarrayDataTypes()`][@stdlib/array/typed-dtypes]: list of typed array data types.

```javascript
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 )`][@stdlib/array/ctors]: array constructors.
-   [`typedarrayComplexCtors( dtype )`][@stdlib/array/typed-complex-ctors]: complex typed array constructors.
-   [`typedarrayCtors( dtype )`][@stdlib/array/typed-ctors]: typed array constructors.

```javascript
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.

-   [`Complex128Array()`][@stdlib/array/complex128]: 128-bit complex number array.
-   [`Complex64Array()`][@stdlib/array/complex64]: 64-bit complex number array.
-   [`convertArraySame( x, y )`][@stdlib/array/convert-same]: convert an array to the same data type as a second input array.
-   [`convertArray( arr, dtype )`][@stdlib/array/convert]: convert an array to an array of a different data type.
-   [`DataView( buffer[, byteOffset[, byteLength]] )`][@stdlib/array/dataview]: constructor which returns a data view representing a provided array buffer.
-   [`arrayDataType( array )`][@stdlib/array/dtype]: return the data type of an array.
-   [`filledarray()`][@stdlib/array/filled]: create a filled array.
-   [`iterator2array( iterator[, out][, mapFcn[, thisArg]] )`][@stdlib/array/from-iterator]: create (or fill) an array from an iterator.
-   [`arrayMinDataType( value )`][@stdlib/array/min-dtype]: determine the minimum array data type of the closest "kind" necessary for storing a provided scalar value.
-   [`arrayNextDataType( [dtype] )`][@stdlib/array/next-dtype]: return the next larger array data type of the same kind.
-   [`typedarraypool()`][@stdlib/array/pool]: allocate typed arrays from a typed array memory pool.
-   [`arrayPromotionRules( [dtype1, dtype2] )`][@stdlib/array/promotion-rules]: return the array data type with the smallest size and closest "kind" to which array data types can be **safely** cast.
-   [`reviveTypedArray( key, value )`][@stdlib/array/reviver]: revive a JSON-serialized typed array.
-   [`arraySafeCasts( [dtype] )`][@stdlib/array/safe-casts]: return a list of array data types to which a provided array data type can be safely cast.
-   [`arraySameKindCasts( [dtype] )`][@stdlib/array/same-kind-casts]: return a list of array data types to which a provided array data type can be safely cast or cast within the same "kind".
-   [`arrayShape( arr )`][@stdlib/array/shape]: determine (nested) array dimensions.
-   [`circarray2iterator( src[, options][, mapFcn[, thisArg]] )`][@stdlib/array/to-circular-iterator]: create an iterator which repeatedly iterates over the elements of an array-like object.
-   [`array2iteratorRight( src[, mapFcn[, thisArg]] )`][@stdlib/array/to-iterator-right]: create an iterator from an array-like object, iterating from right to left.
-   [`array2iterator( src[, mapFcn[, thisArg]] )`][@stdlib/array/to-iterator]: create an iterator from an array-like object.
-   [`typedarray2json( typedarray )`][@stdlib/array/to-json]: return a JSON representation of a typed array.
-   [`sparsearray2iteratorRight( src[, mapFcn[, thisArg]] )`][@stdlib/array/to-sparse-iterator-right]: create an iterator from a sparse array-like object, iterating from right to left.
-   [`sparsearray2iterator( src[, mapFcn[, thisArg]] )`][@stdlib/array/to-sparse-iterator]: create an iterator from a sparse array-like object.
-   [`stridedarray2iterator( N, src, stride, offset[, mapFcn[, thisArg]] )`][@stdlib/array/to-strided-iterator]: create an iterator from a strided array-like object.
-   [`arrayview2iteratorRight( src[, begin[, end]][, mapFcn[, thisArg]] )`][@stdlib/array/to-view-iterator-right]: create an iterator from an array-like object view, iterating from right to left.
-   [`arrayview2iterator( src[, begin[, end]][, mapFcn[, thisArg]] )`][@stdlib/array/to-view-iterator]: create an iterator from an array-like object view.

## Examples

```javascript
var objectKeys = require( '@stdlib/utils/keys' );
var ns = require( '@stdlib/array' );

console.log( objectKeys( ns ) );
```


* * *

## Notice

This package is part of [stdlib][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][stdlib], see the main project [repository][stdlib].

#### Community

[![Chat][chat-image]][chat-url]

---

## License

See [LICENSE][stdlib-license].

## Copyright

Copyright © 2016-2021. The Stdlib [Authors][stdlib-authors].

[npm-image]: http://img.shields.io/npm/v/@stdlib/array.svg
[npm-url]: https://npmjs.org/package/@stdlib/array

[test-image]: https://github.com/stdlib-js/array/actions/workflows/test.yml/badge.svg
[test-url]: https://github.com/stdlib-js/array/actions/workflows/test.yml

[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array/main.svg
[coverage-url]: https://codecov.io/github/stdlib-js/array?branch=main

[dependencies-image]: https://img.shields.io/david/stdlib-js/array.svg
[dependencies-url]: https://david-dm.org/stdlib-js/array/main

[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
[chat-url]: https://gitter.im/stdlib-js/stdlib/

[stdlib]: https://github.com/stdlib-js/stdlib

[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors

[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array/main/LICENSE

[@stdlib/array/complex128]: https://github.com/stdlib-js/array/tree/main/complex128

[@stdlib/array/complex64]: https://github.com/stdlib-js/array/tree/main/complex64

[@stdlib/array/convert-same]: https://github.com/stdlib-js/array/tree/main/convert-same

[@stdlib/array/convert]: https://github.com/stdlib-js/array/tree/main/convert

[@stdlib/array/dataview]: https://github.com/stdlib-js/array/tree/main/dataview

[@stdlib/array/dtype]: https://github.com/stdlib-js/array/tree/main/dtype

[@stdlib/array/filled]: https://github.com/stdlib-js/array/tree/main/filled

[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array/tree/main/from-iterator

[@stdlib/array/min-dtype]: https://github.com/stdlib-js/array/tree/main/min-dtype

[@stdlib/array/next-dtype]: https://github.com/stdlib-js/array/tree/main/next-dtype

[@stdlib/array/pool]: https://github.com/stdlib-js/array/tree/main/pool

[@stdlib/array/promotion-rules]: https://github.com/stdlib-js/array/tree/main/promotion-rules

[@stdlib/array/reviver]: https://github.com/stdlib-js/array/tree/main/reviver

[@stdlib/array/safe-casts]: https://github.com/stdlib-js/array/tree/main/safe-casts

[@stdlib/array/same-kind-casts]: https://github.com/stdlib-js/array/tree/main/same-kind-casts

[@stdlib/array/shape]: https://github.com/stdlib-js/array/tree/main/shape

[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array/tree/main/to-circular-iterator

[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array/tree/main/to-iterator-right

[@stdlib/array/to-iterator]: https://github.com/stdlib-js/array/tree/main/to-iterator

[@stdlib/array/to-json]: https://github.com/stdlib-js/array/tree/main/to-json

[@stdlib/array/to-sparse-iterator-right]: https://github.com/stdlib-js/array/tree/main/to-sparse-iterator-right

[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array/tree/main/to-sparse-iterator

[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array/tree/main/to-strided-iterator

[@stdlib/array/to-view-iterator-right]: https://github.com/stdlib-js/array/tree/main/to-view-iterator-right

[@stdlib/array/to-view-iterator]: https://github.com/stdlib-js/array/tree/main/to-view-iterator

[@stdlib/array/ctors]: https://github.com/stdlib-js/array/tree/main/ctors

[@stdlib/array/typed-complex-ctors]: https://github.com/stdlib-js/array/tree/main/typed-complex-ctors

[@stdlib/array/typed-ctors]: https://github.com/stdlib-js/array/tree/main/typed-ctors

[@stdlib/array/dtypes]: https://github.com/stdlib-js/array/tree/main/dtypes

[@stdlib/array/typed-complex-dtypes]: https://github.com/stdlib-js/array/tree/main/typed-complex-dtypes

[@stdlib/array/typed-dtypes]: https://github.com/stdlib-js/array/tree/main/typed-dtypes

[@stdlib/array/datespace]: https://github.com/stdlib-js/array/tree/main/datespace

[@stdlib/array/incrspace]: https://github.com/stdlib-js/array/tree/main/incrspace

[@stdlib/array/linspace]: https://github.com/stdlib-js/array/tree/main/linspace

[@stdlib/array/logspace]: https://github.com/stdlib-js/array/tree/main/logspace

[@stdlib/array/typed]: https://github.com/stdlib-js/array/tree/main/typed

[@stdlib/array/buffer]: https://github.com/stdlib-js/array/tree/main/buffer

[@stdlib/array/float32]: https://github.com/stdlib-js/array/tree/main/float32

[@stdlib/array/float64]: https://github.com/stdlib-js/array/tree/main/float64

[@stdlib/array/int16]: https://github.com/stdlib-js/array/tree/main/int16

[@stdlib/array/int32]: https://github.com/stdlib-js/array/tree/main/int32

[@stdlib/array/int8]: https://github.com/stdlib-js/array/tree/main/int8

[@stdlib/array/shared-buffer]: https://github.com/stdlib-js/array/tree/main/shared-buffer

[@stdlib/array/uint16]: https://github.com/stdlib-js/array/tree/main/uint16

[@stdlib/array/uint32]: https://github.com/stdlib-js/array/tree/main/uint32

[@stdlib/array/uint8]: https://github.com/stdlib-js/array/tree/main/uint8

[@stdlib/array/uint8c]: https://github.com/stdlib-js/array/tree/main/uint8c

