Zip one or more arrays to an array of objects.
var zip2objects = require( '@stdlib/array/base/zip2objects' );Zips one or more arrays to an array of objects.
var x = [ 1, 2 ];
var y = [ 3, 4 ];
var labels = [ 'x', 'y' ];
var out = zip2objects( [ x, y ], labels );
// returns [ { 'x': 1, 'y': 3 }, { 'x': 2, 'y': 4 } ]The function supports the following parameters:
- arrays: list of arrays to zip.
- labels: list of array labels.
- The function assumes that the list of arrays to be zipped all have the same length.
- The number of provided array labels should equal the number of arrays to be zipped.
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var zeroTo = require( '@stdlib/array/base/zero-to' );
var zip2objects = require( '@stdlib/array/base/zip2objects' );
var x = zeroTo( 10 );
var y = discreteUniform( x.length, -100, 100 );
var labels = [ 'x', 'y' ];
var out = zip2objects( [ x, y ], labels );
// returns [...]