Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

nested2objects

Convert nested arrays to objects.

Usage

var nested2objects = require( '@stdlib/array/base/nested2objects' );

nested2objects( arr, fields )

Converts each nested array to an object.

var x = [ [ 1, 2 ], [ 3, 4 ] ];

var fields = [ 'x', 'y' ];

var out = nested2objects( x, fields );
// returns [ { 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 } ]

The function supports the following parameters:

  • arr: input array containing nested arrays.
  • fields: list of field names.
  • 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.

Examples

var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
var filled2dBy = require( '@stdlib/array/base/filled2d-by' );
var nested2objects = require( '@stdlib/array/base/nested2objects' );

var x = filled2dBy( [ 10, 2 ], discreteUniform( -100, 100 ) );
var fields = [ 'x', 'y' ];

var out = nested2objects( x, fields );
// returns [...]