Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

entries2objects

Convert array entries to an array of objects.

Usage

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

entries2objects( arr, fields )

Converts array entries to an array of objects.

var x = [ 1, 2 ];

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

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

The function supports the following parameters:

  • arr: input array.
  • fields: list of field names.
  • The list of field names should be a two-element array where the first element corresponds to the field name of input array element index and the second element corresponds to the field name of the input array element value.

Examples

var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var entries2objects = require( '@stdlib/array/base/entries2objects' );

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

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