About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
Convert nested arrays to composite views.
To use in Observable,
nested2views = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nested2views@umd/browser.js' )To vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:
var nested2views = require( 'path/to/vendor/umd/array-base-nested2views/index.js' )To include the bundle in a webpage,
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nested2views@umd/browser.js"></script>If no recognized module system is present, access bundle contents via the global scope:
<script type="text/javascript">
(function () {
window.nested2views;
})();
</script>Converts each nested array to a composite view.
var x = [ [ 1, 2 ], [ 3, 4 ] ];
var fields = [ 'x', 'y' ];
var out = nested2views( x, fields );
// returns [ <Object>, <Object> ]
var v0 = out[ 0 ].toJSON();
// returns { 'x': 1, 'y': 2 }
var v1 = out[ 1 ].toJSON();
// returns { 'x': 3, 'y': 4 }
// Mutate the first nested array:
x[ 0 ][ 0 ] = 5;
v0 = out[ 0 ].toJSON();
// returns { 'x': 5, 'y': 2 }
// Set a view property:
out[ 1 ].y = 'beep';
v1 = out[ 1 ].toJSON();
// returns { 'x': 3, 'y': 'beep' }
var y = x.slice();
// returns [ [ 5, 2 ], [ 3, 'beep' ] ]The function supports the following parameters:
- arr: input array.
- fields: list of field names.
Each element in the returned array is a class instance having prototype properties corresponding to the list of field names. As demonstrated in the example above, to convert an element to a regular object, invoke an element's toJSON method. Note, however, that the object returned by an element's toJSON method no longer shares the same memory as the provided input array.
- The function assumes that all nested arrays have the same length.
- The number of provided array labels should equal the length of each nested array.
- Each view in the returned array shares the same memory as the corresponding element in the input array. Accordingly, mutation of either a nested array or a view will mutate the other.
<!DOCTYPE html>
<html lang="en">
<body>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/random-base-discrete-uniform@umd/browser.js"></script>
<script type="text/javascript">
(function () {.factory;
var filled2dBy = require( '@stdlib/array-base-filled2d-by' );
var nested2views = require( '@stdlib/array-base-nested2views' );
var x = filled2dBy( [ 10, 2 ], discreteUniform( -100, 100 ) );
var fields = [ 'x', 'y' ];
var out = nested2views( x, fields );
// returns [...]
})();
</script>
</body>
</html>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.
See LICENSE.
Copyright © 2016-2026. The Stdlib Authors.